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.
Convert Array of Integers to ArrayDeque Java
7.9k views Asked by fire147 At
2
There are 2 answers
0
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);