TreeSet in Java

Veröffentlicht am: 31 März 2018
auf dem Kanal: Sudipto Roy
411
5

What is a TreeSet?
Implements Set interface
It is more like a HashSet which contains unique elements but in a sorted ascending order
Elements are comparable by a default/custom comparator
Access & retrieval times are quite fast
Initialized with a default capacity of 16 & 0.75 load factor

TreeSet Contructors
TreeSet() : Contructs an empty tree that will be sorted based on natual order of elements
TreeSet(Collection c) : Builds a TreeSet from elements of collection c
TreeSet(Compatator c) : Constructs an empty tree that will be sorted on given comparator
TreeSet(SortedSet s) : Constructs from given SortedSet

The elements in TreeSet must be of Comparable type
String & Wrapper classes are Comparable by default
To add user-defined objects, we need to implement Comparable interface
As per Oracle, TreeSet provides log(n) cost time for basic add/remove/contains operation.
While HashSet provide constant O(1) time performance


Auf dieser Seite können Sie das Online-Video TreeSet in Java mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer Sudipto Roy 31 März 2018 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 411 Mal angesehen und es wurde von 5 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!