aicas logo Jamaica 3.4 release 8

java.lang.reflect
Class Array

java.lang.Object
  extended by java.lang.reflect.Array

public final class Array
extends Object

Array provides methods to create instances of array and to access the elements of arrays of different types.

Since:
1.2

Constructor Summary
Array()
           
 
Method Summary
static Object get(Object array, int index)
          get returns the element of a given array at given index.
static boolean getBoolean(Object array, int index)
          getBoolean returns the contents of a boolean array.
static byte getByte(Object array, int index)
          getByte returns the contents of a byte array.
static char getChar(Object array, int index)
          getChar returns the contents of a char array.
static double getDouble(Object array, int index)
          getDouble returns the contents of a double array.
static float getFloat(Object array, int index)
          getFloat returns the contents of a float array.
static int getInt(Object array, int index)
          getInt returns the contents of a int array.
static int getLength(Object array)
          getLength returns the length of the given array instance.
static long getLong(Object array, int index)
          getLong returns the contents of a long array.
static short getShort(Object array, int index)
          getShort returns the contents of a short array.
static Object newInstance(Class<?> componentType, int length)
          Create a new instance of an array with given component type and length.
static Object newInstance(Class<?> componentType, int[] dimensions)
          newInstance
static void set(Object a, int i, Object v)
          set sets an array element to a a given value.
static void setBoolean(Object array, int index, boolean z)
          setBoolean sets an array element to a a given value.
static void setByte(Object array, int index, byte b)
          setByte sets an array element to a a given value.
static void setChar(Object array, int index, char c)
          setChar sets an array element to a a given value.
static void setDouble(Object array, int index, double d)
          setDouble sets an array element to a a given value.
static void setFloat(Object array, int index, float f)
          setFloat sets an array element to a a given value.
static void setInt(Object array, int index, int i)
          setInt sets an array element to a a given value.
static void setLong(Object array, int index, long l)
          setLong sets an array element to a a given value.
static void setShort(Object array, int index, short s)
          setShort sets an array element to a a given value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Array

public Array()
Method Detail

newInstance

public static Object newInstance(Class<?> componentType,
                                 int length)
                          throws NegativeArraySizeException,
                                 IllegalArgumentException,
                                 NullPointerException
Create a new instance of an array with given component type and length.

Parameters:
componentType - the element type for the array. May be either a normal class, an array or a primitive type such as Boolean.TYPE, Byte.TYPE, etc.
length - the number of elements for the new array.
Returns:
a new array instance with result.getClass()getComponentType()==compontentType and getLength(result) == length.
Throws:
NegativeArraySizeException - if length < 0
NullPointerException - if compontentType == null
IllegalArgumentException - if componentType == Void.TYPE

newInstance

public static Object newInstance(Class<?> componentType,
                                 int[] dimensions)
                          throws IllegalArgumentException,
                                 NegativeArraySizeException
newInstance

Parameters:
componentType -
dimensions -
Returns:
the new array
Throws:
IllegalArgumentException
NegativeArraySizeException

getLength

public static int getLength(Object array)
                     throws IllegalArgumentException
getLength returns the length of the given array instance.

Parameters:
array - instance of an array
Returns:
the length of the array
Throws:
IllegalArgumentException - if argument is not an array.
NullPointerException - if array is null.

get

public static Object get(Object array,
                         int index)
                  throws IllegalArgumentException,
                         ArrayIndexOutOfBoundsException
get returns the element of a given array at given index. If the array is a primitive array (such as int[]), the result is boxed into a corresponding instance (such java.lang.Integer).

Parameters:
array - an array
index - an index in array
Returns:
the element array[index]
Throws:
IllegalArgumentException - if array is not an array
ArrayIndexOutOfBoundsException - if index is negative or larger than or equal to getLength(array).
NullPointerException - if array is null.

getBoolean

public static boolean getBoolean(Object array,
                                 int index)
                          throws IllegalArgumentException,
                                 ArrayIndexOutOfBoundsException
getBoolean returns the contents of a boolean array.

Parameters:
array - an array of boolean elements.
index - an index in array
Returns:
the boolean value array[index].
Throws:
IllegalArgumentException - if the array is not of the required type
NullPointerException - if array is null
ArrayIndexOutOfBoundsException - if index is negative or larger than or equal to getLength(array).

getByte

public static byte getByte(Object array,
                           int index)
                    throws IllegalArgumentException,
                           ArrayIndexOutOfBoundsException
getByte returns the contents of a byte array.

Parameters:
array - an array of boolean elements.
index - an index in array
Returns:
the byte value array[index].
Throws:
IllegalArgumentException - if the array is not of the required type
NullPointerException - if array is null
ArrayIndexOutOfBoundsException - if index is negative or larger than or equal to getLength(array).

getChar

public static char getChar(Object array,
                           int index)
                    throws IllegalArgumentException,
                           ArrayIndexOutOfBoundsException
getChar returns the contents of a char array.

Parameters:
array - an array of char elements.
index - an index in array
Returns:
the char value array[index].
Throws:
IllegalArgumentException - if the array is not of the required type
NullPointerException - if array is null
ArrayIndexOutOfBoundsException - if index is negative or larger than or equal to getLength(array).

getShort

public static short getShort(Object array,
                             int index)
                      throws IllegalArgumentException,
                             ArrayIndexOutOfBoundsException
getShort returns the contents of a short array.

Parameters:
array - an array of short elements.
index - an index in array
Returns:
the short value array[index].
Throws:
IllegalArgumentException - if the array is not of the required type
NullPointerException - if array is null
ArrayIndexOutOfBoundsException - if index is negative or larger than or equal to getLength(array).

getInt

public static int getInt(Object array,
                         int index)
                  throws IllegalArgumentException,
                         ArrayIndexOutOfBoundsException
getInt returns the contents of a int array.

Parameters:
array - an array of int elements.
index - an index in array
Returns:
the int value array[index].
Throws:
IllegalArgumentException - if the array is not of the required type
NullPointerException - if array is null
ArrayIndexOutOfBoundsException - if index is negative or larger than or equal to getLength(array).

getLong

public static long getLong(Object array,
                           int index)
                    throws IllegalArgumentException,
                           ArrayIndexOutOfBoundsException
getLong returns the contents of a long array.

Parameters:
array - an array of long elements.
index - an index in array
Returns:
the long value array[index].
Throws:
IllegalArgumentException - if the array is not of the required type
NullPointerException - if array is null
ArrayIndexOutOfBoundsException - if index is negative or larger than or equal to getLength(array).

getFloat

public static float getFloat(Object array,
                             int index)
                      throws IllegalArgumentException,
                             ArrayIndexOutOfBoundsException
getFloat returns the contents of a float array.

Parameters:
array - an array of float elements.
index - an index in array
Returns:
the float value array[index].
Throws:
IllegalArgumentException - if the array is not of the required type
NullPointerException - if array is null
ArrayIndexOutOfBoundsException - if index is negative or larger than or equal to getLength(array).

getDouble

public static double getDouble(Object array,
                               int index)
                        throws IllegalArgumentException,
                               ArrayIndexOutOfBoundsException
getDouble returns the contents of a double array.

Parameters:
array - an array of double elements.
index - an index in array
Returns:
the double value array[index].
Throws:
IllegalArgumentException - if the array is not of the required type
NullPointerException - if array is null
ArrayIndexOutOfBoundsException - if index is negative or larger than or equal to getLength(array).

set

public static void set(Object a,
                       int i,
                       Object v)
                throws IllegalArgumentException,
                       ArrayIndexOutOfBoundsException
set sets an array element to a a given value. The array may be an array of objects or of primitive types. In case of an array of primitive types, the value is unboxed and converted if possible.

Parameters:
a - an array
i - the index to be set
v - the value to be stored at the index
Throws:
IllegalArgumentException - if array is not an array or value could not be unboxed or converted to the array element type.
NullPointerException - if array is null
ArrayIndexOutOfBoundsException - if index is negative or larger than or equal to getLength(array).

setBoolean

public static void setBoolean(Object array,
                              int index,
                              boolean z)
                       throws IllegalArgumentException,
                              ArrayIndexOutOfBoundsException
setBoolean sets an array element to a a given value.

Parameters:
array - an array
index - the index to be set
z - the value to be stored at the index
Throws:
IllegalArgumentException - if array is not an array or z could not be converted to the array element type.
NullPointerException - if array is null
ArrayIndexOutOfBoundsException - if index is negative or larger than or equal to getLength(array).

setByte

public static void setByte(Object array,
                           int index,
                           byte b)
                    throws IllegalArgumentException,
                           ArrayIndexOutOfBoundsException
setByte sets an array element to a a given value.

Parameters:
array - an array
index - the index to be set
b - the value to be stored at the index
Throws:
IllegalArgumentException - if array is not an array or b could not be converted to the array element type.
NullPointerException - if array is null
ArrayIndexOutOfBoundsException - if index is negative or larger than or equal to getLength(array).

setChar

public static void setChar(Object array,
                           int index,
                           char c)
                    throws IllegalArgumentException,
                           ArrayIndexOutOfBoundsException
setChar sets an array element to a a given value.

Parameters:
array - an array
index - the index to be set
c - the value to be stored at the index
Throws:
IllegalArgumentException - if array is not an array or c could not be converted to the array element type.
NullPointerException - if array is null
ArrayIndexOutOfBoundsException - if index is negative or larger than or equal to getLength(array).

setShort

public static void setShort(Object array,
                            int index,
                            short s)
                     throws IllegalArgumentException,
                            ArrayIndexOutOfBoundsException
setShort sets an array element to a a given value.

Parameters:
array - an array
index - the index to be set
s - the value to be stored at the index
Throws:
IllegalArgumentException - if array is not an array or s could not be converted to the array element type.
NullPointerException - if array is null
ArrayIndexOutOfBoundsException - if index is negative or larger than or equal to getLength(array).

setInt

public static void setInt(Object array,
                          int index,
                          int i)
                   throws IllegalArgumentException,
                          ArrayIndexOutOfBoundsException
setInt sets an array element to a a given value.

Parameters:
array - an array
index - the index to be set
i - the value to be stored at the index
Throws:
IllegalArgumentException - if array is not an array or i could not be converted to the array element type.
NullPointerException - if array is null
ArrayIndexOutOfBoundsException - if index is negative or larger than or equal to getLength(array).

setLong

public static void setLong(Object array,
                           int index,
                           long l)
                    throws IllegalArgumentException,
                           ArrayIndexOutOfBoundsException
setLong sets an array element to a a given value.

Parameters:
array - an array
index - the index to be set
l - the value to be stored at the index
Throws:
IllegalArgumentException - if array is not an array or l could not be converted to the array element type.
NullPointerException - if array is null
ArrayIndexOutOfBoundsException - if index is negative or larger than or equal to getLength(array).

setFloat

public static void setFloat(Object array,
                            int index,
                            float f)
                     throws IllegalArgumentException,
                            ArrayIndexOutOfBoundsException
setFloat sets an array element to a a given value.

Parameters:
array - an array
index - the index to be set
f - the value to be stored at the index
Throws:
IllegalArgumentException - if array is not an array or f could not be converted to the array element type.
NullPointerException - if array is null
ArrayIndexOutOfBoundsException - if index is negative or larger than or equal to getLength(array).

setDouble

public static void setDouble(Object array,
                             int index,
                             double d)
                      throws IllegalArgumentException,
                             ArrayIndexOutOfBoundsException
setDouble sets an array element to a a given value.

Parameters:
array - an array
index - the index to be set
d - the value to be stored at the index
Throws:
IllegalArgumentException - if array is not an array or d could not be converted to the array element type.
NullPointerException - if array is null
ArrayIndexOutOfBoundsException - if index is negative or larger than or equal to getLength(array).

aicas logo Jamaica 3.4 release 8

aicas GmbH, Karlsruhe - Germany    www.aicas.com
Copyright 2001-2009 aicas GmbH. All Rights Reserved.