Java array extension/reduction I work with the Oracle JGeometry method which returns (or takes as method argument) 2D segments as double array (x1,y1,x2,y2 ... xn,yn). I need to extend this array to contain 3D segments as double array (x1,y1,z1,x2,y2,z2 ... xn,yn,zn) by default Z value or reduce to 2D (by removing of all Z coordinate). I wrote simple utility methods for making this. Is there any easier or smarter way to do this?
The conversion from 2D to 3D:
public static double[] to3D(double z, double[] inputArray) {
    List&lt;Double&gt; convertedItems = new ArrayList&lt;&gt;();
    for (int i = 0; i &lt; inputArray.length; i++) {
        convertedItems.add(inputArray[i]);
        if ((i + 1) % 2 == 0) {
            convertedItems.add(z);
        }
    }
    return convertedItems.stream().mapToDouble(Double::doubleValue).toArray();
}

The conversion from 3D to 2D:
public static double[] to2D(double[] inputArray) {
    List&lt;Double&gt; convertedItems = new ArrayList&lt;&gt;();
    for (int i = 0; i &lt; inputArray.length; i++) {
       if ((i + 1) % 3 == 0) {
           continue;
       }
       convertedItems.add(inputArray[i]);     
    }
    return convertedItems.stream().mapToDouble(Double::doubleValue).toArray();
}
I would go with primitive Arrays, instead of using Collections and Streams in this case.
public static double[] to3D(double z, double[] in) {
    // Pre-allocated array 1.5 size of the original array
    double[] out = new double[in.length * 3 / 2];
    //loop with a step 2
    for (int i = 0, j = 0; i &lt; in.length; i += 2) {
        out[j++] = in[i];
        out[j++] = in[i + 1];
        out[j++] = z;
    }
    return out;
}

public static double[] to2D(double[] in) {
    // Pre-allocated array 2/3 size of the original array
    double[] out = new double[in.length * 2 / 3];
    //loop with a step 3
    for (int i = 0, j = 0; i &lt; in.length; i += 3) {
        out[j++] = in[i];
        out[j++] = in[i + 1];
    }
    return out;
}

Reasons for using arrays instead of lists: Input and output both are arrays, the target size is known, we only need basic operations and they would be faster in this case.
I hope it helps.