import java.util.HashSet;Output:
import java.util.List;
import java.util.ArrayList;
public class ToArrayList{
public static void main(String[] args) {
// Create a HashSet
HashSethset = new HashSet ();
//add elements to HashSet
hset.add("java");
hset.add("C");
hset.add("C++");
hset.add("Objective C");
hset.add("HTML/CSS");
// print the HashSet
System.out.println("HashSet: "+ hset);
// Create an ArrayList of generic type String
//and pass hashset as argument
ArrayListarraylist = new ArrayList (hset);
// print ArrayList
System.out.println("ArrayList: "+ arraylist);
}
}
HashSet: [HTML/CSS, C, java, Objective C, C++]
ArrayList: [HTML/CSS, C, java, Objective C, C++]
Please disable your ad blocker and refresh the window to use this website.