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();
    }
  }
}
  
Home 
  Java Book 
    Runnable examples