How To Convert LinkedHashset To Array

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

public class LinkedHashSetToArray {

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);

String [] arr = new String[lhs.size()];

//Returns an array containing all of
//the elements in this set
lhs.toArray(arr);

for (String str : arr) {
System.out.println(” Element of array is = “+str);
}

}

}

Leave a Reply

Your email address will not be published. Required fields are marked *

26 + = 31