LinkedHashSet in Java
Advertisements
LinkedHashSet in Java
LinkedHashSet is Implementer class of Set Interface, Which supports hashing mechanism to store the value that means all the elements are stored in the same order as inserted (In unsorted format).
Points to Remember
- LinkedHashSet does not allow duplicate elements.
- LinkedHashSet allows to store heterogeneous elements
- LinkedHashSet is not Synchronized.
- For retrieving elements from LinkedHashSet you can use foreach loop and iterator interface.
- LinkedHashSet allows null values.
Example of LinkedHashSet
import java.util.*; class LHashDemo { public static void main(String args[]) { LinkedHashSet<String> lhs=new LinkedHashSet<String>(); lhs.add("Java"); lhs.add("C-lang"); lhs.add("C++"); lhs.add("Java"); System.out.println(lhs); Iterator i=lhs.iterator(); System.out.println("Forward Direction"); while(l.hasNext()) { System.out.println(i.next()); } } }
Output
Java C-lang C++
Google Advertisment