Convert Array of Integers to ArrayDeque Java

7.9k views Asked by At

How can I to convert Array of Integers to ArrayDeque? For example, instead to add numbers in ArrayDeque with loop, will I can to convert this Array of integers directly to ArrayDeque? Thanks in advance.

2

There are 2 answers

0
Enrico Giurin On
 List<Integer> list = Arrays.asList(array);
 ArrayDeque<Integer> ad = new ArrayDeque<>(list);
0
Zon On

Convert the array into a List first, preserving values type casting. Then create a Deque from a List.

int[] array = new int[]{1,2,3,4,5};
// List<Object> list = Arrays.asList(array);
List<Integer> array = Arrays.stream(array).boxed().collect(Collectors.toList());
Deque<Integer> arrayDeque = new ArrayDeque<>(array);