Java LinkedHashSet Class
Java LinkedHashSet class is a Hashtable and Linked list implementation of the Set interface. It inherits the HashSet class and implements the Set interface.
The important points about the Java LinkedHashSet class are:
Note: Keeping the insertion order in the LinkedHashset has some additional costs, both in terms of extra memory and extra CPU cycles. Therefore, if it is not required to maintain the insertion order, go for the lighter-weight HashMap or the HashSet instead.
Hierarchy of LinkedHashSet class
The LinkedHashSet class extends the HashSet class, which implements the Set interface. The Set interface inherits Collection and Iterable interfaces in hierarchical order.
LinkedHashSet Class Declaration
Let's see the declaration for java.util.LinkedHashSet class.
Constructors of Java LinkedHashSet Class
Java LinkedHashSet Example
Let's see a simple example of the Java LinkedHashSet class. Here you can notice that the elements iterate in insertion order.
One Two Three Four Five
Note: We can also use the enhanced for loop for displaying the elements.
Java LinkedHashSet example ignoring duplicate Elements
Ravi Vijay Ajay
Remove Elements Using LinkeHashSet Class
The hash set is: [Java, T, Point, Good, Website] true After removing the element, the hash set is: [Java, T, Point, Website] false
Java LinkedHashSet Example: Book
101 Let us C Yashwant Kanetkar BPB 8 102 Data Communications & Networking Forouzan Mc Graw Hill 4 103 Operating System Galvin Wiley 6