import java.util.HashSet;输出:
public class ToArray{
public static void main(String[] args) {
// 创建一个 HashSet
HashSeths = new HashSet ();
//填充元素
hs.add(E1”);
hs.add(E2”);
hs.add(E3”);
hs.add(E4”);
hs.add(E5”);
// display
System.out.println(HashSet: ”+ hs);
// 创建 array
String[] array = new String[hs.size()];
hs.toArray(array);
// 数组 display
System.out.print(array: ”);
for(String e: array){
System.out.print(e+ ”);
}
}
}
HashSet: [E2, E1, E4, E3, E5]
array: E2 E1 E4 E3 E5
Please disable your ad blocker and refresh the window to use this website.