List of usage examples for java.util WeakHashMap put
public V put(K key, V value)
From source file:Main.java
public static void main(String[] args) { WeakHashMap<String, String> hashMap = new HashMap<String, String>(); hashMap.put("1", "first"); hashMap.put("2", "two"); hashMap.put("3", "from java2s.com"); Map<String, String> weakHashMap = new WeakHashMap<String, String>(hashMap); }
From source file:Main.java
public static void main(String[] args) { WeakHashMap<String, String> weakHashMap = new WeakHashMap<String, String>(); weakHashMap.put("1", "first"); weakHashMap.put("2", "two"); weakHashMap.put("3", "from java2s.com"); // check existence of value "from java2s.com" System.out.println("Checking value 'three'"); System.out.println(weakHashMap.containsValue("from java2s.com")); }
From source file:Main.java
public static void main(String[] args) { WeakHashMap<String, String> weakHashMap = new WeakHashMap<String, String>(); weakHashMap.put("1", "first"); weakHashMap.put("2", "two"); weakHashMap.put("3", "from java2s.com"); // check key value System.out.println("Checking value for key 1"); System.out.println(weakHashMap.containsKey("1")); }
From source file:Main.java
public static void main(String[] args) { WeakHashMap<String, String> weakHashMap = new WeakHashMap<String, String>(); weakHashMap.put("1", "first"); weakHashMap.put("2", "two"); weakHashMap.put("3", "from java2s.com"); // check existence of value for key 2 System.out.println("Checking value for key 2"); System.out.println(weakHashMap.get("2")); }
From source file:Main.java
public static void main(String[] args) { WeakHashMap<String, String> weakHashMap = new WeakHashMap<String, String>(); weakHashMap.put("1", "first"); weakHashMap.put("2", "two"); weakHashMap.put("3", "from java2s.com"); // printing the contents of the Map System.out.println("Contents of the Map"); System.out.println(weakHashMap); // populating the set Set set = weakHashMap.keySet(); System.out.println("Contents of the set"); System.out.println(set);// ww w . j a va 2s. co m }
From source file:Main.java
public static void main(String[] args) { WeakHashMap<String, String> weakHashMap = new WeakHashMap<String, String>(); weakHashMap.put("1", "first"); weakHashMap.put("2", "two"); weakHashMap.put("3", "from java2s.com"); // print the contents System.out.println("Contents in the Map"); System.out.println(weakHashMap); // call clear() method System.out.println("Clear the Map"); weakHashMap.clear();/*from www . j a v a 2 s. com*/ // again print the contents System.out.println("Contents in the Map"); System.out.println(weakHashMap); }
From source file:Main.java
public static void main(String[] args) { WeakHashMap<String, String> weakHashMap = new WeakHashMap<String, String>(); weakHashMap.put("1", "first"); weakHashMap.put("2", "two"); weakHashMap.put("3", "from java2s.com"); // printing the Map System.out.println("Map: " + weakHashMap); // returns a Set view of the Map Set set = weakHashMap.entrySet(); // printing the set System.out.println("Set: " + set); // change Map value weakHashMap.put("3", "new value"); // print Map and set System.out.println("Changed Map: " + weakHashMap); System.out.println("Changed Set: " + set); }
From source file:Main.java
public static void main(String[] args) { WeakHashMap<String, String> weakHashMap = new WeakHashMap<String, String>(); System.out.println("Putting values into the Map"); weakHashMap.put("1", "first"); weakHashMap.put("2", "two"); weakHashMap.put("3", "from java2s.com"); // checking the size of the Map System.out.println("Map size: " + weakHashMap.size()); }
From source file:Main.java
public static void main(String[] args) { WeakHashMap<String, String> weakHashMap = new WeakHashMap<String, String>(); System.out.println("Putting values into the Map"); weakHashMap.put("1", "first"); weakHashMap.put("2", "two"); weakHashMap.put("3", "from java2s.com"); // checking the size of the Map System.out.println("Map values: " + weakHashMap); Collection col = weakHashMap.values(); System.out.println("Collection values: " + col); }
From source file:Main.java
public static void main(String[] args) { WeakHashMap<String, String> weakHashMap = new WeakHashMap<String, String>(); System.out.println("Putting values into the Map"); weakHashMap.put("1", "first"); weakHashMap.put("2", "two"); weakHashMap.put("3", "from java2s.com"); // checking Map System.out.println("Map: " + weakHashMap); // remove value at key 2 System.out.println("Returned value: " + weakHashMap.remove("2")); System.out.println("New Map: " + weakHashMap); }