TreeSet in java

TreeSet(Since Java 1.2) Underlying data structure is balanced tree. Duplicates are not allowed. Insertion order is not preserved since objects will be inserted based on some sorting technique. Null insertion is not possible in a non-empty TreeSet. We will get NullPointerException if we add. Heterogeneous objects are not allowed.  We will get ClassCastException if we […]

HashSet and LinkedHashSet

HashSet (Since Java 1.2):  HashSet is achild interface of Set.  Underlying data structure is HashTable.(Internally it’s a HashMap. See HashTable code)  Insertion order is not preserved.  Duplicates are not allowed.  Allows null element ( only one since set will not allow duplicates).  Default initial capacity is 16.  Default load factor is 0.75f.  Threshold = capacity […]