List of usage examples for java.util WeakHashMap WeakHashMap
public 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"); // 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>(); 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>(); 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:Weak.java
public static void main(String args[]) { final Map map = new WeakHashMap(); map.put(new String("Java2s"), "www.java2s.com"); Runnable runner = new Runnable() { public void run() { while (map.containsKey("Java2s")) { try { Thread.sleep(500); } catch (InterruptedException ignored) { }//from w ww .ja v a2 s . co m System.out.println("Waiting"); System.gc(); } } }; Thread t = new Thread(runner); t.start(); System.out.println("Main waiting"); try { t.join(); } catch (InterruptedException ignored) { } }
From source file:Main.java
public static void main(String[] args) { WeakHashMap<String, String> weakHashMap = new WeakHashMap<String, String>(); // check map contents System.out.println("Checking the map entries"); System.out.println("Map is empty: " + weakHashMap.isEmpty()); 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 is empty: " + weakHashMap.isEmpty()); }
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); }
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); // putting value at key 2 String str = (String) weakHashMap.put("2", "newvalue"); System.out.println("Returned value: " + str); System.out.println("New Map: " + weakHashMap); }
From source file:Main.java
public static void main(String args[]) { final Map<String, String> map = new WeakHashMap<String, String>(); map.put(new String("A"), "B"); Runnable runner = new Runnable() { public void run() { while (map.containsKey("A")) { try { Thread.sleep(500); } catch (InterruptedException ignored) { }// www .j av a2 s.c o m System.gc(); } } }; Thread t = new Thread(runner); t.start(); try { t.join(); } catch (InterruptedException ignored) { } }
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();/* ww w.ja v a 2 s. co m*/ // again print the contents System.out.println("Contents in the Map"); System.out.println(weakHashMap); }