Java TreeSet Class

TreeSet is class under Set interface of collection framework. It implements NavigableSet interface which extends SortedSet interface. Elements are ordered by a Comparator which is provided at set creation time or by natural ordering. It maintains the ascending sorting order. TreeSet is not synchronized so if multiple threads accessing it concurrently and any one modifies set entry then … Read more

Java SortedSet Interface

SortedSet interface extends Set interface in collection framework of java. As name suggest, It provides total ordering on elements of Set. Set elements will be ordered using their natural ordering or using a comparator interface. All the elements entries of SortedSet must implement Comparable interface. All the elements of SortedSet must be comparable. So e1.compareTo(e2) … Read more

HashSet in Java Collection Example

HashSet is a class of collection framework which extends AbstractSet class and implements the Set interface. HasSet doesn’t guarantee that elements order will remain same over the time and returned in any random order. HasSet doesn’t allow duplicate values. If you try to insert duplicate, It will overwrite. HasSet allows to store null values. HasSet … Read more

Java LinkedHashSet Class

LinkedHashSet Class extends extends HashSet class and Implements Set interface in collection interface hierarchy. LinkedHashSet implementation differs from HashSet as it maintains doubly-linked list running through all of its entries. It maintains element’s entries in set as per it’s insertion order. So it will allow you insertion order iteration over the set. So when you iterate over LinkedHashSet, … Read more