如果没有指定方法 toArray,如何使用 toArray() 将 hash Set 转换为数组?
2022-09-02 11:34:52
看看java api for java collections framework,我在HashSet中找不到toArray()方法,抽象类Set中有toArray()方法。
class Ideone {
public static void main (String[] args) throws java.lang.Exception {
Set x = new HashSet();
x.add(4);
//ArrayList<Integer> y = x.toArray(); this does not work !
int[] y = x.toArray();//this does not work!
System.out.println(x.toArray());//this gives some weird stuff printed : Ljava.lang.Object;@106d69c
}
}
如果没有指定 toArray() 如何将哈希集转换为数组?