Search code examples
javaarraysdoublearraydeque

ArrayDeque to array


I have built an arraydeque and want to pass those Double values as an array to a constructor. The constructor is built to process the array values individually to a certain condition.

When using arraydeque its not allowing me to retrieve those double values (Iterater .next for loop) and store them in an array.

Are there any suggestions to correct this?


Solution

  • Try this:

    Deque<Double> deque;
    Double[] array = Double[deque.size()];
    int count = 0;
    for (Iterator<Double> i = deque.iterator(); i.hasNext();) {
        array[count++] = i.next();
    }