i want to change the natural order of the collection , but dont have the complete understanding of how to use the Comparator iterface.Plz help How will the compare be used in this case???
import java.util.*; class Testsorting{ public static void main(String[] args) {
HashMap hmap = new HashMap(); hmap.put("1","anna"); hmap.put("2","anna"); hmap.put("3","soorya"); System.out.println(hmap); SortedMap sortmap = new TreeMap(hmap); System.out.println(sortmap);
TreeMap tmap = new TreeMap(); tmap.put("1","how"); tmap.put("2","do"); tmap.put("3","udodo"); System.out.println(tmap); SortedMap sortmap2 = new TreeMap(tmap); System.out.println(sortmap2); Comparator comp = new Comparator(); System.out.println(comp.compare(hmap,tmap)); } }
faiza haris
Ranch Hand
Joined: Oct 17, 2000
Posts: 173
posted
0
Thanx.......... u seem to have a very good understanding!! leme play more with the code and comeup with more q�s for u thanx alot