Java Array Length Get arrayLength(Object o)

Here you can find the source of arrayLength(Object o)

Description

array Length

License

Apache License

Declaration

public static int arrayLength(Object o) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    public static int arrayLength(Object o) {
        if (o instanceof Object[])
            return ((Object[]) o).length;
        else if (o instanceof boolean[])
            return ((boolean[]) o).length;
        else if (o instanceof float[])
            return ((float[]) o).length;
        else if (o instanceof double[])
            return ((double[]) o).length;
        else if (o instanceof char[])
            return ((char[]) o).length;
        else if (o instanceof byte[])
            return ((byte[]) o).length;
        else if (o instanceof short[])
            return ((short[]) o).length;
        else if (o instanceof int[])
            return ((int[]) o).length;
        else if (o instanceof long[])
            return ((long[]) o).length;
        throw new ClassCastException(notArrayType(o));
    }/*from   www .  j av a2s .c om*/

    private static String notArrayType(Object o) {
        return (o == null ? "null" : o.getClass().getName()) + " is not an array type";
    }
}

Related

  1. arrayBounds(int arrayLength, int offset, int length)
  2. arrayCounter(T[] x)
  3. arrayLenght(Object array)
  4. arrayLength(Object array, int defaultIfNull, int defaultIfNotArray)
  5. arrayLength(Object[] ar)
  6. length(byte[] array)
  7. length(byte[] array)
  8. length(double[] a)