Java LinkedHashSet class:
- contains
unique elements only like HashSet. It extends HashSet class and implements
Set interface.
- maintains
insertion order.
Hierarchy of LinkedHashSet class:
Example
of LinkedHashSet class:
1. import java.util.*;
2. class TestCollection10{
3. public static void main(String args[]){
4.
5. LinkedHashSet<String> al=new LinkedHashSet<String>();
6. al.add("Ravi");
7. al.add("Vijay");
8. al.add("Ravi");
9. al.add("Ajay");
10.
11. Iterator<String> itr=al.iterator();
12. while(itr.hasNext()){
13. System.out.println(itr.next());
14. }
15. }
16. }
Output:>Ravi
Vijay
Ajay
No comments:
Post a Comment