import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class HashSetToList {
public static void main(String[] args) {
Set<String> hs = new HashSet<String>();
hs.add("java");
hs.add("php");
hs.add("html");
hs.add("javascript");
hs.add("mysql");
//print hashset
System.out.println("hashset = "+hs);
List<String> list = new ArrayList<String>(hs);
System.out.println("list from hashset = "+list);
}
}
Output:
hashset = [javascript, php, html, java, mysql]
list from hashset = [javascript, php, html, java, mysql]
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class HashSetToList {
public static void main(String[] args) {
Set<String> hs = new HashSet<String>();
hs.add("java");
hs.add("php");
hs.add("html");
hs.add("javascript");
hs.add("mysql");
//print hashset
System.out.println("hashset = "+hs);
List<String> list = new ArrayList<String>(hs);
System.out.println("list from hashset = "+list);
}
}
Output:
hashset = [javascript, php, html, java, mysql]
list from hashset = [javascript, php, html, java, mysql]
No comments:
Post a Comment