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);
}
}
}
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);
}
}
}
No comments:
Post a Comment