Swan Lake Beta3 is here.
import ballerina/io;

public function main() {
    int[] v = [1, 2, 3];

    // `v[i]` does indexed access.
    int n = v[0];

    io:println(n);

    // `v[i]` is an `lvalue`.
    v[3] = 4;

    // `len` will be 3.
    int len = v.length();

}

Arrays

T[] is an array of T. Arrays are mutable. == and != on arrays is deep: two arrays are equal if they have the same members in the same order. Ordering is lexicographical based on the ordering of the members. Langlib arr.length() function gets the length; arr.setLength(n) sets the length.

import ballerina/io;
public function main() {
    int[] v = [1, 2, 3];
    int n = v[0];

v[i] does indexed access.

    io:println(n);
    v[3] = 4;

v[i] is an lvalue.

    int len = v.length();

len will be 3.

}
bal run arrays.bal
1
import ballerina/io;

public function main() {
    int[] v = [1, 2, 3];

    // `v[i]` does indexed access.
    int n = v[0];

    io:println(n);

    // `v[i]` is an `lvalue`.
    v[3] = 4;

    // `len` will be 3.
    int len = v.length();

}

Arrays

T[] is an array of T. Arrays are mutable. == and != on arrays is deep: two arrays are equal if they have the same members in the same order. Ordering is lexicographical based on the ordering of the members. Langlib arr.length() function gets the length; arr.setLength(n) sets the length.

import ballerina/io;
public function main() {
    int[] v = [1, 2, 3];
    int n = v[0];

v[i] does indexed access.

    io:println(n);
    v[3] = 4;

v[i] is an lvalue.

    int len = v.length();

len will be 3.

}
bal run arrays.bal
1
Subscribe to the newsletter

In the creation of Ballerina, we were inspired by so many technologies. Thank you to all that have come before us (and forgive us if we missed one): Java, Go, C, C++, D, Rust, Haskell, Kotlin, Dart, TypeScript, JavaScript, Python, Perl, Flow, Swift, Elm, RelaxNG, NPM, Crates, Maven, Gradle, Kubernetes, Docker, Envoy, Markdown, GitHub and WSO2.

Cookie Policy

This website uses cookies so that we can provide you with the best user experience. Read our Cookie Policy to find out more.

If you wish to disable cookies you can do so from your browser.

I Understand