wood burning stoves 2.0*
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 Java 8 in Action this week in the Java 8 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: 3394
    
    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
TreeSet
Comparable and Comparator
Comparator
doubt in treeset...
List String Contains Method