4

How can i append element to end of an array directly other than using following code.

string[] array = ["1","2"];
array[lengthof-1] = "3";
Chamil E
  • 478
  • 3
  • 10
Dan.M
  • 71
  • 1
  • Bellarina? What's that? – Ruan Mendes Jul 06 '18 at 16:28
  • Possible duplicate of [equivalent to push() or pop() for arrays?](https://stackoverflow.com/questions/4537980/equivalent-to-push-or-pop-for-arrays) – Ruan Mendes Jul 06 '18 at 16:29
  • It a Cloud Native Programming Language. https://ballerina.io/ – Dan.M Jul 06 '18 at 16:30
  • I don’t get it, their page says you draw stuff and it works but then it comes back and shows yet another brick of code. – Nick M Jul 06 '18 at 17:15
  • Ballerina (https://ballerina.io/) is a cloud-native programming language. It is a general-purpose programming language that is better suited for network data such as JSON, XML, tables with first-class abstractions that'll ease your microservices and other applications development that involve integrations with network services. Here is the language specification. https://ballerina.io/res/Ballerina-Language-Specification-WD-2018-05-01.pdf. Examples guide https://ballerina.io/learn/by-example/ – Sameera Jayasoma Jul 06 '18 at 18:59

2 Answers2

4

Here is the only possible way at the moment.

   int[] a = [1,2,3,4,5,6];
   a[lengthof a] = 7;

There is no built-in append function at the moment.

Sameera Jayasoma
  • 1,545
  • 8
  • 12
0

You can simply create a function for that.

function append(int[] arr,int val){       
arr[arr.length()] = val;
}

Then you can use it in your code

yashod perera
  • 375
  • 3
  • 3