Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
faiza haris
Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 173
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic