TreeSet | HashSet | LinkedHashSet |
- public class TreeSet
- extends AbstractSet
- implements SortedSet, Cloneable, Serializable
| - public class HashSet
- extends AbstractSet
- implements Set, Cloneable, Serializable
| - public class LinkedHashSet
- extends HashSet
- implements Set, Cloneable, Serializable
|
unique values | unique values | Unique values |
It stores its elements in a red-black tree | It stores its elements in a hash table | is implemented as a hash table with a linked list running through it |
Order : ascending order | undefined | insertion order |
Performance : Slow | better than LinkedHashSet | has fast adding to the start of the list, and fast deletion from the interior via iteration |
operations (add , remove and contains ) | operations (add, remove, contains and size) | operations (add, contains and remove) |
add, addAll,ceiling,clear,clone,comparator,contains, descendingIterator,descendingSet,first,floor, hashSet,higher,isEmpty,iterator,last,lower,pollFirst, remove,size,subSet,tailSet | add, clear, clone, contains, isEmpty,iterator, remove, size | add, clear, clone, contains, isEmpty,iterator, remove, size |
From AbstractSet:
equals, hashCode, removeAll | equals, hashCode, removeAll | equals, hashCode, removeAll |
containsAll, retainAll, toArray, toArray,toString | AbstractCollection:
addAll, containsAll, retainAll, toArray,toArray, toString | addAll, containsAll, retainAll, toArray,toArray, toString |
Set:
containsAll, equals, hashCode, removeAll,retainAll, toArray, toArray | addAll, containsAll, equals, hashCode,removeAll, retainAll, toArray, toArray | add, addAll, clear, contains, containsAll,equals, hashCode, isEmpty, iterator, remove,removeAll, retainAll, size, toArray, toArray |