Collection FrameWork Series - LinkedHashSet and SortedSet explained in detail

Опубликовано: 25 Июль 2026
на канале: Learn Java
416
10

You can learn Java with me as the Java Programming language is being made easily. It would take a period of minimum three months and maximum 6 months to master Java. I would recommend you to watch all my videos to crack any software interviews that would require Java Programming language as a primary skill.

LinkedHashSet:
============
1. LinkedHashSet is a child class of HashSet
2. It was introduced in the JDK 1.4 version
3. LinkedHashSet follows the insertion order.
4. LinkedHashSet internal data structure is "HashTable+LinkedList"
5. It is non-synchronized in nature
6. It is high in performance.
7. It is not a thread safe.
8. It cant be used in Multithreaded environment.
9. Data consistency is not maintained.
10. It is used for frequent search operations.

SortedSet:-
=========
1. It is a child interface to Set interface.
2. It was introduced in the JDK1.2 version
3. It follows the Sorting order
4. It is not following insertion order.
5. It is not allowing duplicates
6. It will not allow heterogeneous elements and if any heterogeneous element is added, it will throw an exception called java.lang.ClassCastException.
7. It will not allow even a single null value and, when you add so, you will get the exception as java.lang.NullPointerException
8. It allows comparable object by default , if we want to add non comparable objects than we must use java.util.comparable interface.

Methods inside the SortedSet:-
=========================
1. public Object first();
2. public Object last();
3. public SortedSet headSet(Object obj));
4. public SortedSet tailSet(Object obj));
5. public SortedSet subSet(Object obj));