jballerina.java.arrays
Module jballerina.java.arrays
Definitions
ballerina/jballerina.java.arrays Ballerina library
Functions
fromHandle
Returns a Ballerina array for a handle that holds a Java array.
int[] array = <int[]> check arrays:fromHandle(arrayHandle, "int");
Parameters
- array handle - The
handle, which refers to the Java array
- jType string - The
stringparameter provided to specify the Java array element type
- bType string (default "default") - The optional
stringparameter provided to specify the Ballerina array element type
Return Type
- any[]|error - Ballerina array
any[]|errorfor the provided handle
get
function get(handle array, int index) returns handleReturns a handle, which refers to the element at the specified index in the given Java array. This function
completes abruptly with a panic if the specified handle refers to a Java null or if the handle does not refer
to a Java array.
handle words = getSortedArray(); handle firstWord = arrays:get(words, 0);
Parameters
- array handle - The
handle, which refers to the Java array
- index int - The index of the element to be returned
Return Type
- handle - The
handle, which refers to the element at the specified position in the Java array
getLength
function getLength(handle array) returns intReturns the length of the given Java array.
handle array = getArray(); int length = arrays:getLength(array);
Parameters
- array handle - The
handle, which refers to the Java array
Return Type
- int - The length of the given Java array
newInstance
function newInstance(handle classType, int... dimensions) returns handleReturns a new Java array instance with the specified element type and dimensions. This function completes abruptly
with a panic if the specified handle refers to a Java null or if zero dimensions have been provided.
handle stringClass = check java:getClass("java.lang.String"); handle StrArray = arrays:newInstance(stringClass, 4);
Parameters
- classType handle - The element type of the array
- dimensions int... - The dimensions of the array
Return Type
- handle - The new Java array instance
set
function set(handle array, int index, handle element)Replaces the indexed element at the specified index in the given Java array with the specified element. This
function completes abruptly with a panic if the specified handle refers to a Java null or if the handle does
not refer to a Java array.
handle strArray = getStringArray(); arrays:set(strArray, 0, java:fromString("Ballerina"));
Parameters
- array handle - The
handle, which refers to the Java array
- index int - The index of the element to be replaced
- element handle - The element to be stored at the specified index
toHandle
Returns a handle value representation for a Ballerina array.
handle handleValue = check arrays:toHandle(array, "char");
Parameters
- array any[] - Ballerina array which is to be converted to a handle reference
- jType string - Java class name or the primitive type of the array elements referenced by the handle
Return Type
- handle|error - The
handle|errorafter the conversion
Import
import ballerina/jballerina.java.arrays;Metadata
Released date: 11 months ago
Version: 1.5.0
License: Apache-2.0
Compatibility
Platform: java21
Ballerina version: 2201.11.0-20241209-162400-0c015833
GraalVM compatible: Yes
Pull count
Total: 1
Current verison: 0
Weekly downloads
Keywords
java
arrays
Contributors