Java int[] array to HashSet

前端 未结 7 2102
感情败类
感情败类 2020-12-29 20:54

I have an array of int:

int[] a = {1, 2, 3};

I need a typed set from it:

Set s;

If I do th

相关标签:
7条回答
  • 2020-12-29 21:46

    Or you could easly use Guava to convert int[] to List<Integer>:

    Ints.asList(int...)

    asList

    public static List<Integer> asList(int... backingArray)

    Returns a fixed-size list backed by the specified array, similar to Arrays.asList(Object[]). The list supports List.set(int, Object), but any attempt to set a value to null will result in a NullPointerException.

    The returned list maintains the values, but not the identities, of Integer objects written to or read from it. For example, whether list.get(0) == list.get(0) is true for the returned list is unspecified.

    0 讨论(0)
提交回复
热议问题