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 Performance and the fly likes TreeSet that uses the same Comparator? 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 » Performance
Bookmark "TreeSet that uses the same Comparator?" Watch "TreeSet that uses the same Comparator?" New topic
Author

TreeSet that uses the same Comparator?

Jon Camilleri
Ranch Hand

Joined: Apr 25, 2008
Posts: 659

"The API documentation explains that you need
not override the equals method but that doing so may yield improved performance in some
cases. For example, the addAll method of the TreeSet class can work more effectively if you
add elements from another set that uses the same comparator."

Core Java Vol.I (8th Edition) P.674.

Can you clarify and provide an example?


Jon
Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 3366
    
    9
If two trees use the same ordering of their elements, adding all of the elements from one tree to another can be made a lot simpler, because a lot of the elements may already be in the correct order, and the tree only has to see which chunks of elements go where.

How can the set tell that another set uses the same ordering? If the comparator it uses equals the comparator of the other set.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: TreeSet that uses the same Comparator?
 
Similar Threads
doubt in treeset...
Comparable and Comparator
Comparator
List String Contains Method
TreeSet