JavaArray.JavaArray with an arbitrary data type using the newInstance method of the Array class:
public static Object newInstance(Class componentType,
int length)
throws NegativeArraySizeException
JavaArray object is an instance of a Java array that is created in or passed to JavaScript. JavaArray is a wrapper for the instance; all references to the array instance are made through the JavaArray.
You must specify a class object, such as one returned by java.lang.Object.forName, for the componentType parameter of newInstance when you use this method to create an array. You cannot use a JavaClass object for the componentType parameter.
Use zero-based indexes to access the elements in a JavaArray object, just as you do to access elements in an array in Java. For example:
var javaString = new java.lang.String("Hello world!");
var byteArray = javaString.getBytes();
byteArray[0] // returns 72
byteArray[1] // returns 101
Any Java data brought into JavaScript is converted to JavaScript data types. When the JavaArray is passed back to Java, the array is unwrapped and can be used by Java code. See the Client-Side JavaScript Guide for more information about data type conversions.
| Property |
Description
The number of elements in the Java array represented by |
|---|
| Method |
Description
| |
|---|
JavaArray in JavaScript.
In this example, the JavaArray byteArray is created by the java.lang.String.getBytes method, which returns an array.
var javaString = new java.lang.String("Hello world!");
var byteArray = javaString.getBytes();
Example 2. Instantiating a JavaArray in JavaScript with the newInstance method.
Use a class object returned by java.lang.Class.forName as the argument for the newInstance method, as shown in the following code:
var dataType = java.lang.Class.forName("java.lang.String")
var dogs = java.lang.reflect.Array.newInstance(dataType, 5)
JavaArray object.Array.length, JavaArray.length is a read-only property. You cannot change the value of the JavaArray.length property because Java arrays have a fixed number of elements.
Array.length
toString method is inherited from the Object object and returns the following value:
[object JavaArray]
Last Updated: 05/28/99 11:59:40