📜  将 hashset 转换为数组 - Java 代码示例

📅  最后修改于: 2022-03-11 14:52:17.345000             🧑  作者: Mango

代码示例1
//    First of all, you shouldn't use raw types.
//    Use :
    Set set = new HashSet<>();
    set.add(4);
    set.add(1);
//    Then convert to array :
    Integer[] arr = x.toArray(new Integer[set.size()]);
//    Using x.toArray() would give you an Object[].