I have a Queue<Integer> declared as Queue<Integer> queue=new LinkedList();, I need to reverse the elments order in it, and then convert it into an int array. I wrote below code:
Collections.reverse((List)queue);
int[] res=queue.stream().mapToInt(Integer::intValue).toArray();
This code has two problems:
- the explict casting
(List)queue; - I wonder if there is a one line solution.
So do we have any more elegant way to do this?
Clearification of the problem:
Whether the queue is reversed is not important. An int array of the reversed elements is what I need.