Java Array Dimension Get arrayDimension(String clsName)

Here you can find the source of arrayDimension(String clsName)

Description

Computes the dimension of the array class specified by name.

License

Open Source License

Parameter

Parameter Description
clsName name, e.g., <code>[[I</code> or <code>[LString;</code>

Return

the dimension of the array class specified by name

Declaration

private static int arrayDimension(String clsName) 

Method Source Code

//package com.java2s;

public class Main {
    /**//from  ww  w  .  j  a  v  a2  s . co m
     * Computes the dimension of the array class specified by name.
     *
     * @param clsName name, e.g.,
     * <code>[[I</code> or
     * <code>[LString;</code>
     * @return the dimension of the array class specified by name
     */
    private static int arrayDimension(String clsName) {

        int arrayDim = 0;

        // is array
        if (clsName.startsWith("[")) {

            // compute array dim
            for (int i = 0; i < clsName.length(); i++) {
                if (clsName.charAt(i) != '[') {
                    break;
                }

                arrayDim = i + 1;
            }
        }

        return arrayDim;
    }
}

Related

  1. arrayDim(Class c)
  2. arrayDimensions(Class arrayClass)
  3. arrayDimensions(Class c)
  4. arraysDims(String[] arr)