opendap/src/main/java/opendap/dap/DArray.java
private int printArray(PrintWriter os, int index, int dims, int shape[],
                           int offset) {
        if (dims == 1) {
            os.print("{");
            for (int i = 0; i < shape[offset] - 1; i++) {
                getPrimitiveVector().printSingleVal(os, index++);
                os.print(", ");
            }
            getPrimitiveVector().printSingleVal(os, index++);
            os.print("}");
            return index;
        } else {
            os.print("{");
            for (int i = 0; i < shape[offset] - 1; i++) {
                index = printArray(os, index, dims - 1, shape, offset + 1);
                os.print(",");
            }
            index = printArray(os, index, dims - 1, shape, offset + 1);
            os.print("}");
            return index;
        }
    }
private int printArray(PrintWriter os, int index, int dims, int shape[],
                           int offset) {
        if (dims == 1) {
            os.print("{");
            for (int i = 0; i < shape[offset] - 1; i++) {
                getPrimitiveVector().printSingleVal(os, index++);
                os.print(", ");
            }
            getPrimitiveVector().printSingleVal(os, index++);
            os.print("}");
            return index;
        } else {
            os.print("{");
            for (int i = 0; i < shape[offset] - 1; i++) {
                index = printArray(os, index, dims - 1, shape, offset + 1);
                os.print(",");
            }
            index = printArray(os, index, dims - 1, shape, offset + 1);
            os.print("}");
            return index;
        }
    }
Print an array. This is a private member function.

@param os     is the stream used for writing
@param index  is the index of VEC to start printing
@param dims   is the number of dimensions in the array
@param shape  holds the size of the dimensions of the array.
@param offset holds the current offset into the dimension array.
@return the number of elements written.