Package Summary  Overview Summary

class:Array [NONE]


  • public final class Array
    extends Object
    
    The Array class provides static methods to dynamically create and access Java arrays.

    Array permits widening conversions to occur during a get or set operation, but throws an IllegalArgumentException if a narrowing conversion would occur.

    Since:
    1.1

method:newInstance(java.lang.Class,int) [NONE]

  • newInstance

    public static Object newInstance​(Class<?> componentType,
                                     int length)
                              throws NegativeArraySizeException
    
    Creates a new array with the specified component type and length. Invoking this method is equivalent to creating an array as follows:
     int[] x = {length};
     Array.newInstance(componentType, x);
     

    The number of dimensions of the new array must not exceed 255.

    Parameters:
    componentType - the Class object representing the component type of the new array
    length - the length of the new array
    Returns:
    the new array
    Throws:
    NullPointerException - if the specified componentType parameter is null
    IllegalArgumentException - if componentType is Void.TYPE or if the number of dimensions of the requested array instance exceed 255.
    NegativeArraySizeException - if the specified length is negative

method:newInstance(java.lang.Class,int...) [NONE]

  • newInstance

    public static Object newInstance​(Class<?> componentType,
                                     int... dimensions)
                              throws IllegalArgumentException,
                                     NegativeArraySizeException
    
    Creates a new array with the specified component type and dimensions. If componentType represents a non-array class or interface, the new array has dimensions.length dimensions and componentType as its component type. If componentType represents an array class, the number of dimensions of the new array is equal to the sum of dimensions.length and the number of dimensions of componentType. In this case, the component type of the new array is the component type of componentType.

    The number of dimensions of the new array must not exceed 255.

    Parameters:
    componentType - the Class object representing the component type of the new array
    dimensions - an array of int representing the dimensions of the new array
    Returns:
    the new array
    Throws:
    NullPointerException - if the specified componentType argument is null
    IllegalArgumentException - if the specified dimensions argument is a zero-dimensional array, if componentType is Void.TYPE, or if the number of dimensions of the requested array instance exceed 255.
    NegativeArraySizeException - if any of the components in the specified dimensions argument is negative.

method:getLength(java.lang.Object) [NONE]

  • getLength

    public static int getLength​(Object array)
                         throws IllegalArgumentException
    
    Returns the length of the specified array object, as an int.
    Parameters:
    array - the array
    Returns:
    the length of the array
    Throws:
    IllegalArgumentException - if the object argument is not an array

method:get(java.lang.Object,int) [NONE]

method:getBoolean(java.lang.Object,int) [NONE]

method:getByte(java.lang.Object,int) [NONE]

method:getChar(java.lang.Object,int) [NONE]

method:getShort(java.lang.Object,int) [NONE]

method:getInt(java.lang.Object,int) [NONE]

method:getLong(java.lang.Object,int) [NONE]

method:getFloat(java.lang.Object,int) [NONE]

method:getDouble(java.lang.Object,int) [NONE]

method:set(java.lang.Object,int,java.lang.Object) [NONE]

  • set

    public static void set​(Object array,
                           int index,
                           Object value)
                    throws IllegalArgumentException,
                           ArrayIndexOutOfBoundsException
    
    Sets the value of the indexed component of the specified array object to the specified new value. The new value is first automatically unwrapped if the array has a primitive component type.
    Parameters:
    array - the array
    index - the index into the array
    value - the new value of the indexed component
    Throws:
    NullPointerException - If the specified object argument is null
    IllegalArgumentException - If the specified object argument is not an array, or if the array component type is primitive and an unwrapping conversion fails
    ArrayIndexOutOfBoundsException - If the specified index argument is negative, or if it is greater than or equal to the length of the specified array

method:setBoolean(java.lang.Object,int,boolean) [NONE]

method:setByte(java.lang.Object,int,byte) [NONE]

method:setChar(java.lang.Object,int,char) [NONE]

method:setShort(java.lang.Object,int,short) [NONE]

method:setInt(java.lang.Object,int,int) [NONE]

method:setLong(java.lang.Object,int,long) [NONE]

method:setFloat(java.lang.Object,int,float) [NONE]

method:setDouble(java.lang.Object,int,double) [NONE]

© 2018 Oracle Corporation and/or its affiliates