ballerina/jballerina.java.arrays

Overview

This module provides APIs to create new Java array instances, get elements from arrays, set elements, etc.

Create a Java array instance

1handle stringClass = check java:getClass("java.lang.String");
2handle StrArray = arrays:newInstance(stringClass, 4);

Get an element from a Java array

1handle firstWord = arrays:get(words, 0);

Replace an element in a Java array

1arrays:set(strArray, 0, java:fromString("Ballerina"));

Get Java array length

1int length = arrays:getLength(array);

Get a Ballerina array from a Java array

1int[] array = <int[]> check arrays:fromHandle(arrayHandle, "int");

Get a Java array from a Ballerina array

1handle handleValue = check arrays:toHandle(bArray, "char");

Functions

[6]

fromHandle

Returns a Ballerina array for a handle that holds a Java array.

get

Returns a handle, which refers to the element at the specified index in the given Java array.

getLength

Returns the length of the given Java array.

newInstance

Returns a new Java array instance with the specified element type and dimensions.

set

Replaces the indexed element at the specified index in the given Java array with the specified element.

toHandle

Returns a handle value representation for a Ballerina array.