How to convert queue to double[][] in java?

I am trying to convert queue<double[]> to double[][] using java 8 stream. There are lots of literatures showing a way to convert queue<double> to double[] in many ways but I failed to convert the double[] to double[][].

How to achieve issue above?


You can use this method queue.toArray(new Double[0][0]);.
Be careful.Do not use nonparametric overloaded method queue.toArray().Because it can’t convert to Double[][] but Obejct[].

For example:

LinkedBlockingQueue<Double[]> linkedBlockingQueue = new LinkedBlockingQueue<>();
        linkedBlockingQueue.put(new Double[]{1.1, 1.2});
        linkedBlockingQueue.put(new Double[]{2.1, 2.2});
        Double[][] doubleTwoDimensionArray = linkedBlockingQueue.toArray(new Double[0][0]);

The new Double[0][0] only be used to appoint the type of conversion.

Leave a Reply

Your email address will not be published. Required fields are marked *