aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Collections Comparator....in how much detail?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Collections Comparator....in how much detail??" Watch "Collections Comparator....in how much detail??" New topic
Author

Collections Comparator....in how much detail??

faiza haris
Ranch Hand

Joined: Oct 17, 2000
Posts: 173
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
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Collections Comparator....in how much detail??
 
Similar Threads
Util2
Map Store only last value
EL expressions
Storing objects in hashmap
HashMap