LinkedHashSet Class:- Earlier we have discussed HashSet class. In this tutorial we will learn about LinkedHashSet class.
- It is a class which extends HashSet class and implements Set interface.
- Maintains insertion order.
- Contains unique elements
Syntax:
LinkedHashSet <String> hs = new LinkedHashSet <String>();
Sample Program of LinkedHashSet:
- It is a class which extends HashSet class and implements Set interface.
- Maintains insertion order.
- Contains unique elements
Syntax:
LinkedHashSet <String> hs = new LinkedHashSet <String>();
Sample Program of LinkedHashSet:
import
java.util.LinkedHashSet;
public class
LinkedHashSetDemo {
public static void main(String[] args) {
LinkedHashSet
<String> hs = new LinkedHashSet <String>();
hs.add("John");
hs.add("Miller");
hs.add("Denis");
hs.add("Javed");
hs.add("John");
System.out.println("Elements
of LinkedHashSet class:" + hs);
}
}
OutPut:
Elements of LinkedHashSet class:[John, Miller, Denis, Javed]
No comments:
Post a Comment