Convert Set to List in Java

import java.util.*;

public class ConvertSet2List{
    public static void main(String[] args) {
    Set<Object> set = new HashSet<Object>();
        set.add("JavaStuff.in");
        set.add(new Long(5));
        set.add(new Date());
        set.add(6);
       /*Convert the Set to a List can be done by passing the Set
          instance into the constructor of a List implementation class                      such as ArrayList. */
        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);
        }
    }
}


Enter your email address to get our daily JOBS & INTERVIEW FAQ's Straight to your Inbox.

Make sure to activate your subscription by clicking on the activation link sent to your email