This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
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 EJB 3 in Action this week in the EJB and other Java EE Technologies 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: 4523
    
    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: 7036
    
  16

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?
Artlicles by Winston can be found here
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how comparator works
 
Similar Threads
Using a Comparator in Collections
TreeMap and Sorting
Repositioning an object in a TreeSet?
Doubt in collection Framework
Bubble Sort Set using Comparator