public static void generalFunctionsDemo(String args[]) { TreeMap tm1 = new TreeMap(); System.out.println("tm1 isEmpty() before adding elements: " + tm1.isEmpty()); tm1.put("one", 1); tm1.put("apple", "red"); tm1.put("two", 2); tm1.put("three", 3); tm1.put("four", 4); System.out.println("tm1 isEmpty() after adding elements: " + tm1.isEmpty()); System.out.println("Key/value pairs of tm1:" + tm1); System.out.println("\napple key exists: " + tm1.containsKey("apple")); System.out.println("two key exists: " + tm1.containsKey("two")); System.out.println("red value exists: " + tm1.containsValue("red")); System.out.println("2 value exists: " + tm1.containsValue(2)); System.out.println("\nValue of three: " + tm1.get("three")); System.out.println("Value of four: " + tm1.get("four")); System.out.println("\nNo. of elements before removal: " + tm1.size()); tm1.remove("one"); System.out.println("No. of elements after removal: " + tm1.size()); tm1.clear(); System.out.println("No. of elements after clear(): " + tm1.size()); }
Thursday, 19 January 2012
TreeMap Progam - General Functions
Labels:
Collections,
treeMap
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment