Set

TreeSet Java Add Print Clone Elements

Two Programs exists on TreeSet Java. TreeSet General: General operations like printing the elements in natural order (the default behavior of SortedSet, the super class of TreeSet), extracting a part of a set, creating generics TreeSet Java etc. are performed. TreeSet Special: Operations like cloning the TreeSet, iterating elements with Iterator and the methods like …

TreeSet Java Add Print Clone Elements Read More »

TreeSet Example Add, Print, Extract Elements

Two Programs exists on TreeSet. TreeSet General: General operations like printing the elements in natural order (the default behavior of SortedSet, the super class of TreeSet), extracting a part of a set, creating generics TreeSet etc. are performed. TreeSet Special: Operations like cloning the TreeSet, iterating elements with Iterator and the methods like retainAll(), addAll(), …

TreeSet Example Add, Print, Extract Elements Read More »

TreeSet Tutorial Constructors Methods

TreeSet is derived from SortedSet interface. We know earlier, SortedSet is derived from Set and Set is derived from Collection. A complete hierarchy is available at "Java Collections Interfaces Hierarchy". TreeSet is very powerful as it can make use of all the methods of Collection (like iterator() and add()); stores only unique elements, a feature …

TreeSet Tutorial Constructors Methods Read More »

SortedSet interface Java

SortedSet interface is derived from Set interface. Set interface is very unique in the whole collections hierarchy. All the derived classes of Set interface like HashSet and TreeSet does not allow duplicate elements, a unique characteristic of all collections classes. The SortedSet interface adds one more feature of returning the elements in ascending order (known …

SortedSet interface Java Read More »

HashSet Example addAll containAll retainAll Iterator

Two programs are given on HashSet with different functionality. HashSet General: In this program, the general methods like contains, equals, add, size, remove, toArray and hashCode usage is illustrated. Elements are printed with foreach loop. HashSet Operations: In this program, Iterator for printing the elements of HashSet is used. The methods like addAll(), clear(), retainAll(), …

HashSet Example addAll containAll retainAll Iterator Read More »

HashSet Tutorial add remove equals contains hashCode

Two programs are given on HashSet Tutorial with different functionality. HashSet General: In this program, the general methods like contains(), equals(), add(), size(), remove(), toArray() and hashCode() usage is illustrated. Elements are printed with foreach loop. HashSet Operations: Iterator for printing the elements of HashSet is used. Methods like addAll, clear, retainAll, containsAll and toString …

HashSet Tutorial add remove equals contains hashCode Read More »

HashSet Tutorial

HashSet Tutorial: HashSet implements the Set interface. HashSet uses hash table, at the background, for storage of elements; uses a mechanism called hashing. No guarantee of returning the elements in the same order when called different times or insertion order. HashSet permits null element. But the set should contain only one null value as duplicates …

HashSet Tutorial Read More »