Contents Prev Next Up


3.6 Managing Arrays

newarray

Allocate new array
 
newarray = 188
atype

Stack: ..., size => result

size must be an integer. It represents the number of elements in the new array.

atype is an internal code that indicates the type of array to allocate. Possible values for atype are as follows:
T_BOOLEAN4
T_CHAR5
T_FLOAT6
T_DOUBLE7
T_BYTE8
T_SHORT9
T_INT10
T_LONG11

A new array of atype, capable of holding size elements, is allocated, and result is a reference to this new object. Allocation of an array large enough to contain size items of atype is attempted. All elements of the array are initialized to zero.

If size is less than zero, a NegativeArraySizeException is thrown. If there is not enough memory to allocate the array, an OutOfMemoryError is thrown.

anewarray

Allocate new array
 
anewarray = 189
indexbyte1
indexbyte2
of references to objects

Stack: ..., size=> result

size must be an integer. It represents the number of elements in the new array.

indexbyte1 and indexbyte2 are used to construct an index into the constant pool of the current class. The item at that index is resolved. The resulting entry must be a class.

A new array of the indicated class type and capable of holding size elements is allocated, and result is a reference to this new object. Allocation of an array large enough to contain size items of the given class type is attempted. All elements of the array are initialized to null.

If size is less than zero, a NegativeArraySizeException is thrown. If there is not enough memory to allocate the array, an OutOfMemoryError is thrown.

anewarray is used to create a single dimension of an array of object references. For example, to create

new Thread[7]
the following code is used:

bipush 7
anewarray <Class "java.lang.Thread">
anewarray can also be used to create the first dimension of a multi-dimensional array. For example, the following array declaration:

new int[6][]
is created with the following code:

bipush 6
anewarray <Class "[I">
See CONSTANT_Class in the "Class File Format" chapter for information on array class names.

multianewarray

Allocate new multi-dimensional array
 
multianewarray = 197
indexbyte1
indexbyte2
dimensions

Stack: ..., size1 size2...sizen => result

Each size must be an integer. Each represents the number of elements in a dimension of the array.

indexbyte1 and indexbyte2 are used to construct an index into the constant pool of the current class. The item at that index is resolved. The resulting entry must be an array class of one or more dimensions.

dimensions has the following aspects:

 new int[6][3][]
the following code is used:

 bipush 6
 bipush 3
 multianewarray <Class "[[[I"> 2
If any of the size arguments on the stack is less than zero, a NegativeArraySizeException is thrown. If there is not enough memory to allocate the array, an OutOfMemoryError is thrown.

The result is a reference to the new array object.

Note: More explanation needed about how this is an array of arrays.

Note: It is more efficient to use newarray or anewarray when creating a single dimension.

See CONSTANT_Class in the "Class File Format" chapter for information on array class names.

arraylength

 
arraylength = 190
Get length of array

Stack: ..., objectref => ..., length

objectref must be a reference to an array object. The length of the array is determined and replaces objectref on the top of the stack.

If the objectref is null, a NullPointerException is thrown.

iaload

Load integer from array
 
iaload = 46

Stack: ..., arrayref, index => ..., value

arrayref must be a reference to an array of integers. index must be an integer. The integer value at position number index in the array is retrieved and pushed onto the top of the stack.

If arrayref is null a NullPointerException is thrown. If index is not within the bounds of the array an ArrayIndexOutOfBoundsException is thrown.

laload

Load long integer from array
 
laload = 47

Stack: ..., arrayref, index => ..., value-word1, value-word2

arrayref must be a reference to an array of long integers. index must be an integer. The long integer value at position number index in the array is retrieved and pushed onto the top of the stack.

If arrayref is null a NullPointerException is thrown. If index is not within the bounds of the array an ArrayIndexOutOfBoundsException is thrown.

faload

Load single float from array
 
faload = 48

Stack: ..., arrayref, index => ..., value

arrayref must be a reference to an array of single-precision floating point numbers. index must be an integer. The single-precision floating point number value at position number index in the array is retrieved and pushed onto the top of the stack.

If arrayref is null a NullPointerException is thrown. If index is not within the bounds of the array an ArrayIndexOutOfBoundsException is thrown.

daload

Load double float from array
 
daload = 49

Stack: ..., arrayref, index => ..., value-word1, value-word2

arrayref must be a reference to an array of double-precision floating point numbers. index must be an integer. The double-precision floating point number value at position number index in the array is retrieved and pushed onto the top of the stack.

If arrayref is null a NullPointerException is thrown. If index is not within the bounds of the array an ArrayIndexOutOfBoundsException is thrown.

aaload

Load object reference from array
 
aaload = 50

Stack: ..., arrayref, index => ..., value

arrayref must be a reference to an array of references to objects. index must be an integer. The object reference at position number index in the array is retrieved and pushed onto the top of the stack.

If arrayref is null a NullPointerException is thrown. If index is not within the bounds of the array an ArrayIndexOutOfBoundsException is thrown.

baload

Load signed byte from array.
 
baload = 51

Stack: ..., arrayref, index => ..., value

arrayref must be a reference to an array of signed bytes. index must be an integer. The signed byte value at position number index in the array is retrieved, expanded to an integer, and pushed onto the top of the stack.

If arrayref is null a NullPointerException is thrown. If index is not within the bounds of the array an ArrayIndexOutOfBoundsException is thrown.

caload

Load character from array
 
caload = 52

Stack: ..., arrayref, index => ..., value

arrayref must be a reference to an array of characters. index must be an integer. The character value at position number index in the array is retrieved, zero-extended to an integer, and pushed onto the top of the stack.

If arrayref is null a NullPointerException is thrown. If index is not within the bounds of the array an ArrayIndexOutOfBoundsException is thrown.

saload

Load short from array
 
saload = 53

Stack: ..., arrayref, index => ..., value

arrayref must be a reference to an array of short integers. index must be an integer. The ;signed short integer value at position number index in the array is retrieved, expanded to an integer, and pushed onto the top of the stack.

If arrayref is null, a NullPointerException is thrown. If index is not within the bounds of the array an ArrayIndexOutOfBoundsException is thrown.

iastore

Store into integer array
 
iastore = 79

Stack: ..., arrayref, index, value => ...

arrayref must be a reference to an array of integers, index must be an integer, and value an integer. The integer value is stored at position index in the array.

If arrayref is null, a NullPointerException is thrown. If index is not within the bounds of the array an ArrayIndexOutOfBoundsException is thrown.

lastore

Store into long integer array
 
lastore = 80

Stack: ..., arrayref, index, value-word1, value-word2 => ...

arrayref must be a reference to an array of long integers, index must be an integer, and value a long integer. The long integer value is stored at position index in the array.

If arrayref is null, a NullPointerException is thrown. If index is not within the bounds of the array, an ArrayIndexOutOfBoundsException is thrown.

fastore

Store into single float array
 
fastore = 81

Stack: ..., arrayref, index, value => ...

arrayref must be an array of single-precision floating point numbers, index must be an integer, and value a single-precision floating point number. The single float value is stored at position index in the array.

If arrayref is null, a NullPointerException is thrown. If index is not within the bounds of the array an ArrayIndexOutOfBoundsException is thrown.

dastore

Store into double float array
 
dastore = 82

Stack: ..., arrayref, index, value-word1, value-word2 => ...

arrayref must be a reference to an array of double-precision floating point numbers, index must be an integer, and value a double-precision floating point number. The double float value is stored at position index in the array.

If arrayref is null, a NullPointerException is thrown. If index is not within the bounds of the array an ArrayIndexOutOfBoundsException is thrown.

aastore

Store into object reference array
 
aastore = 83

Stack: ..., arrayref, index, value => ...

arrayref must be a reference to an array of references to objects, index must be an integer, and value a reference to an object. The object reference value is stored at position index in the array.

If arrayref is null, a NullPointerException is thrown. If index is not within the bounds of the array, an ArrayIndexOutOfBoundsException is thrown.

The actual type of value must be conformable with the actual type of the elements of the array. For example, it is legal to store an instance of class Thread in an array of class Object, but not vice versa. (See the Java Language Specification for information on how to determine whether a object reference is an instance of a class.) An ArrayStoreException is thrown if an attempt is made to store an incompatible object reference.

Note: Mustn't refer to the Java Language Specification; give semantics here.

bastore

Store into signed byte array
 
bastore = 84

Stack: ..., arrayref, index, value => ...

arrayref must be a reference to an array of signed bytes, index must be an integer, and value an integer. The integer value is stored at position index in the array. If value is too large to be a signed byte, it is truncated.

If arrayref is null, a NullPointerException is thrown. If index is not within the bounds of the array an ArrayIndexOutOfBoundsException is thrown.

castore

Store into character array
 
castore = 85

Stack: ..., arrayref, index, value => ...

arrayref must be an array of characters, index must be an integer, and value an integer. The integer value is stored at position index in the array. If value is too large to be a character, it is truncated.

If arrayref is null, a NullPointerException is thrown. If index is not within the bounds of [the array an ArrayIndexOutOfBoundsException is thrown.

sastore

 
sastore = 86
Store into short array

Stack: ..., array, index, value => ...

arrayref must be an array of shorts, index must be an integer, and value an integer. The integer value is stored at position index in the array. If value is too large to be an short, it is truncated.

If arrayref is null, a NullPointerException is thrown. If index is not within the bounds of the array an ArrayIndexOutOfBoundsException is thrown.


Contents Prev Next Up