Java Collection -Set

<I>Set does not contain duplicates. randomly stores elements. does not permits null elements. How to make your list synchronised? Collections.synchronizedSet(yourSetObject) Classes  <C>TreeSet Sorts element by natural order. rest of the properties are same as specified by interface Set Internally it is implemented using the TreeMap.        Main purpose is for sorting the stores elements.        …

Read More Read More

TreeSet Vs HashSet

Treeset and hashset both belong to set and obey the rule of maintaining uinique elements . But treeset comes with some more added advantage. TreeSet gives ability to sort elements with the help of the compareTo(). More examples on http://www.shivapreals.tech/allpost/java-tutorial/java-collection-tutorial/ HashSet allows null elements. Treeset never allows null.   Hashset is faster as it is not dealing with sorting of elements. Treeset has sorting capability so it is somewhat slow.   To compare equality hashSet uses equals() while on…

Read More Read More