Contains on TreeSet versus another set

Is the contains method on TreeSet(since it is already sorted by default) faster than HashSet?

I ask that Collections.binarySearchpretty quickly if the list is sorted, so I think that perhaps the contains method for the TreeSet might be the same.

+3
source share
1 answer

From javadoc TreeSet :

This implementation provides a guaranteed log (n) time value for basic operations (add, delete and contain).

From javadoc HashSet :

(, , ), , - .

, - .

( JDK 1.7), treeet.contains( hashtree) treemap.containsKey( hashmap). Key - hashmap ( ), , node node treemap, compareTo. , .

, (, , ) , 1 , 2- , . HashSet 50 .

+5

All Articles