All for Joomla All for Webmasters

LinkedHashSet class

  • contains unique elements only like HashSet. It extends HashSet class and implements Set interface.
  • maintains insertion order.

Example of LinkedHashSet class:

  1. import java.util.*;
  2. class TestCollection10{
  3.  public static void main(String args[]){
  4.   LinkedHashSet<String> al=new LinkedHashSet<String>();
  5.   al.add(“Ravi”);
  6.   al.add(“Vijay”);
  7.   al.add(“Ravi”);
  8.   al.add(“Ajay”);
  9.   Iterator<String> itr=al.iterator();
  10.   while(itr.hasNext()){
  11.    System.out.println(itr.next());
  12.   }
  13.  }
  14. }
Output:>Ravi
       Vijay
       Ajay
PinIt
submit to reddit

Leave a Reply

Top