import java.util.HashSet;
import java.util.List;
import java.util.ArrayList;
class ConvertHashsettoArraylist{
public static void main(String[] args) {
// Create a HashSet
HashSet<String> hset = new HashSet<String>();
//add elements to HashSet
hset.add("JAVA");
hset.add("DOTNET");
hset.add("HADOOP");
hset.add("C/C++");
hset.add("ORACLE");
// Displaying HashSet elements
System.out.println("HashSet contains: "+ hset);
// Creating a List of HashSet elements
List<String> list = new ArrayList<String>(hset);
// Displaying ArrayList elements
System.out.println("ArrayList contains: "+ list);
}
}
OUTPUT:
HashSet contains: [C/C++, DOTNET, ORACLE, JAVA, HADOOP]
ArrayList contains: [C/C++, DOTNET, ORACLE, JAVA, HADOOP]
import java.util.List;
import java.util.ArrayList;
class ConvertHashsettoArraylist{
public static void main(String[] args) {
// Create a HashSet
HashSet<String> hset = new HashSet<String>();
//add elements to HashSet
hset.add("JAVA");
hset.add("DOTNET");
hset.add("HADOOP");
hset.add("C/C++");
hset.add("ORACLE");
// Displaying HashSet elements
System.out.println("HashSet contains: "+ hset);
// Creating a List of HashSet elements
List<String> list = new ArrayList<String>(hset);
// Displaying ArrayList elements
System.out.println("ArrayList contains: "+ list);
}
}
OUTPUT:
HashSet contains: [C/C++, DOTNET, ORACLE, JAVA, HADOOP]
ArrayList contains: [C/C++, DOTNET, ORACLE, JAVA, HADOOP]
No comments:
Post a Comment