The javaArrayObj Command


Usage:

javaArrayObj ?-noconvert? option ?arg arg ...?

If a Java object handle represents an instance of an array object, then it is also the name of a Tcl command that takes the following options: length, get, set, getrange, and setrange. If any other option is chosen, the behavior of the array object command defaults to that of the object command described above. The -noconvert flag can only be used with the get, getrange, and default options. The options for this command behave as follows:

length
Returns the number of elements in the Java object. If the object is a multi-dimensional array, the number of elements in the first dimension is returned.

get ?-noconvert? indexList
Returns the value stored in the multi-dimensional array cell specified by indexList. The i'th element in indexList specifies the index value of the i'th array dimension. For example, the result of the following commands is the string "easy".
set a [java::new {String[]} {6} {Java scripting is easy in Tcl}]
$a get 3
To retrieve a k-dimensional subarray of an n-dimensional array, specifiy an indexList with n - k index values. For example, the following commands result in subArray containing a 1-dimensional char array handle that refers to a[1][0], the internal value of which is {e f}.
set a [java::new {char[][][]} {2 2 2} {{{a b} {c d}} {{e f} {g h}}}]
set subArray [$a get {1 0}]

set indexList value
Sets the multi-dimensional array cell specified by indexList to value. The i'th element in indexList specifies the index value of the i'th array dimension. If value is not the correct data type, an error is returned. For example, the following commands result in a having an internal value of {Tcl is a great scripting language!}.
set a [java::new {String[]} {6} {Tcl is a good scripting language!}]
$a set 3 great

getrange ?-noconvert? ?indexList ?count?
Returns the list of objects corresponding to the specified range of the array. The range starts at the element specified by indexList and spans a maximum of count elements or the remaining elements of the subarray. The indexList defaults to 0, and count defaults to the length of the subarray. For example, the result of the following commands is the list {scripting is easy}.
set a [java::new {String[]} {6} {Java scripting is easy in Tcl}]
$a getrange 1 3
To retrieve a k-dimensional subarray of an n-dimensional array, specifiy an indexList with n - k index values. For example, the following commands result in pair containing two 1-dimensional char array handles that refer to a[0][1] and a[0][2], the internal values of which are {c d} and {e f} respectively.
set a [java::new {char[][][]} {2 3 2} {{{a b} {c d} {e f}} {{g h} {i j} {k l}}}]
set pair [$a getrange {0 1} 2]

setrange ?indexList? ?count? valueList
Sets the range of array elements to elements of valueList. The range starts at the element specified by indexList and spans a minimum of count elements, the remaining elements of the subarray, or the size of valueList. If an element of valueList in the replacement range is not the correct data type, an error is returned. For example, the following commands result in a having an internal value of {Tcl is an excellent scripting language!}
set a [java::new {String[]} {6} {Tcl is a good scripting language!}]
$a setrange 2 {an excellent}

The Conversions section describes the result and possible error conditions of the object command, including the effect of the optional -noconvert flag.

Copyright © 1997-1998 Sun Microsystems, Inc.