appending an array of int to an ArrayList of <Integer>

arraylist, java

Solution

Using `Arrays.asList(ints)` as suggested by others won't work (it'll give a list of `int[]` rather than a list of `Integer`).

The only way I can think of is to add the elements one by one:

    for (int val : ints) {
        list.add(val);
    }

If you can turn your `int[]` into `Integer[]`, then you can use `addAll()`:

    list.addAll(Arrays.asList(ints));

Problem

Is there a shortcut to add (in fact append ) an array of int to an ArrayList? for the following example ``` ArrayList<Integer> list=new ArrayList<Integer>(); int[] ints={2,4,5,67,8}; ``` Or do I have to add the elements of ints one by one to list?

Original source