「Java入門」java.util.WeakHashMapのサンプル
サンプルコード
package study;
import java.util.HashMap;
import java.util.Map.Entry;
import java.util.WeakHashMap;
public class MapEntryDemo {
public static void main(String[] args) {
HashMap<String, String> ctmp = new HashMap<String, String>();
WeakHash Map<String, String> cft = new WeakHashMap<String, String>();
cft.put(“DataA", “Java");
cft.put(“DataB", “Scala");
cft.put(“DataC", “Java");
System.out.println(“WeakHashMap:");
System.out.println(cft);
System.out.println(“");
for (Entry<String, String> entry : cft.entrySet()) {
ctmp.put(entry.getKey(), entry.getValue());
}
System.out.println(“HashMap:");
System.out.println(ctmp);
System.out.println(“");
}
}
結果
WeakHashMap:
{DataA=Java, DataB=Scala, DataC=Java}
HashMap:
{DataB=Scala, DataC=Java, DataA=Java}