Source Code : Creating a Set That Retains Order-of-Insertion

Java Is Open Source Programming Language You Can Download From Java and Java Libraries From http://www.oracle.com. Click Here to download
We provide this code related to title for you to solve your developing problem easily. Libraries which is import in this program you can download from http://www.oracle.com. Click Here or search from google with Libraries Name you get jar file related it

Creating a Set That Retains Order-of-Insertion

 

import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.Set;

public class Main {
  public static void main(String[] argv) throws Exception {

    Set<String> set = new LinkedHashSet<String>();

    // Add some elements
    set.add("1");
    set.add("2");
    set.add("3");
    set.add("2");

    // List the elements
    for (Iterator it = set.iterator(); it.hasNext();) {
      Object o = it.next();
    }
  }
}

   
  

Thank with us