Friday, March 13, 2009

How would you guarantee sorting of objects in a class that implements

Question :How would you guarantee sorting of objects in a class that implements
Map interface? (JavaUtil)

Answer :TreeMap class implements SortedMap interface and provides the
guarantee of sorted objects in ascending key order.
TreeMap treeMap = new TreeMap();
treeMap.put("abc", "xyz");
treeMap.put("xyz", "abc");
treeMap.put("def","xyz");
System.out.println("treeMap::"+treeMap);

No comments: