Convert Set into List in Java

Description

The following code shows how to convert Set into List.

Example


    //ww  w  .  j a  v a  2  s . c om

 
import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class Main {
  public static void main(String[] args) {
    Set<Object> set = new HashSet<Object>();
    set.add("A");
    set.add(new Long(10));
    set.add(new Date());

    List<Object> list = new ArrayList<Object>(set);
    for (int i = 0; i < list.size(); i++) {
      Object o = list.get(i);
      System.out.println("Object = " + o);
    }
  }
}

The code above generates the following result.





















Home »
  Java Tutorial »
    Java Collection »




Java ArrayList
Java Collection
Java Comparable
Java Comparator
Java HashMap
Java HashSet
Java Iterator
Java LinkedHashMap
Java LinkedHashSet
Java LinkedList
Java List
Java ListIterator
Java Map
Queue
Java Set
Stack
Java TreeMap
TreeSet