6

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.

fire147
  • 63
  • 1
  • 3
  • 9

2 Answers2

8
 List<Integer> list = Arrays.asList(array);
 ArrayDeque<Integer> ad = new ArrayDeque<>(list);
Enrico Giurin
  • 2,183
  • 32
  • 30
0

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);
Zon
  • 18,610
  • 7
  • 91
  • 99