Tuesday 2 June 2015

How to Convert a LinkedHashSet to ArrayList



import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;

public class LinkedHashSetToList {
   
    public static void main(String[] args) {
       
        Set<String> lhs = new LinkedHashSet<String>();
       
        lhs.add("mumbai");
        lhs.add("delhi");
        lhs.add("kolkata");
        lhs.add("chandigarh");
        lhs.add("dehradun");
       
        //print linkedhashset
        System.out.println(" lhs is = "+lhs);
       
        List<String> list = new ArrayList<String>(lhs);
       
       
        // print arraylist
        System.out.println(" ArrayList Is = "+list);
       
    }

}



Output:


 lhs is = [mumbai, delhi, kolkata, chandigarh, dehradun]

ArrayList Is = [mumbai, delhi, kolkata, chandigarh, dehradun]

No comments:

Post a Comment