aspose file tools*
The moose likes Java in General and the fly likes how comparator works Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "how comparator works" Watch "how comparator works" New topic
Author

how comparator works

shriram iyer
Ranch Hand

Joined: Dec 10, 2003
Posts: 43
my question is based on following program



when i use ts.add("G") how compare method in MyComp is called?

thanks
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4664
    
    5

To find out, I would go through the source of the method and trace the execution. TreeSet#add(...) calls TreeMap#put(...) on a TreeMap constructed with the supplied comparator, and that comparator is used in put(...)


luck, db
There are no new questions, but there may be new answers.
shriram iyer
Ranch Hand

Joined: Dec 10, 2003
Posts: 43
Darryl Burke wrote:To find out, I would go through the source of the method and trace the execution. TreeSet#add(...) calls TreeMap#put(...) on a TreeMap constructed with the supplied comparator, and that comparator is used in put(...)


do you mean following method



i have doubt in above method.what t.left ,t.right means

thanks
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 8418
    
  23

shriram iyer wrote:i have doubt in above method.what t.left ,t.right means

They are the next node downward to the "left" or "right", but for a full explanation you should probably Google something like "B-tree algorithm".

Winston


Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how comparator works