Array data structure
An array is a data structure that can store more than 1 value at the same time. It can be 1-dimensional like a list, 2-dimensional like a spreadsheet, 3-dimensional like a cube, or multidimensional. The length and number of dimensions are virtually unlimited.
Syntax
Methods
buildString
Return a string containing the contents of the array, separated by the delimiter string.
Declaration
String {instance}.buildString(String delimiter)
Examples
String[] strings;
strings.pushBack("Alpha");
strings.pushBack("Beta");
strings.pushBack("Charlie");
String delimitedString = nstrings.buildString(",");
printLine(delimitedString);
//prints Alpha,Beta,Charlie
clear
Removes all array elements. Array length afterwards is 0.
Declaration
Void {instance}.clear()
Examples
String[] userPlans;
userPlans.pushBack("Standard");
userPlans.pushBack("Sales");
printLine("Before clear length: " + userPlans.length().toString());
userPlans.clear();
printLine("After clear length: " + userPlans.length().toString());
//prints:
//Before clear length: 2
//After clear length: 0
first()
Returns the first element in the array. Same as [0].
Declaration
{type} {instance}.first()
Examples
String[] userPlans;
userPlans.pushBack("Standard");
userPlans.pushBack("Sales");
String first = userPlans.first();
printLine(first); //prints Standard
fromJsonString(String)
This function will append to the array the contents of the supplied JSON formatted string. Same functionality as fromXMLNode(XMLNode n), but it will parse the provided string directly without having to use parseJSON() yourself. Please note, this function will not clear the array, but rather append to it.
Declaration
Void {instance}.fromJsonString(String json)
Examples
String[] strings;
strings.fromJsonString('["Alpha", "Beta", "Charlie"]');
insert
Adds an element at the specified index.
Declaration
Void {instance}.insert(Integer index, {type} value)
Examples
String[5] userPlans;
userPlans.pushBack("Enterprise");
userPlans.pushBack("Standard");
userPlans.insert(0, "Marketing");
userPlans.insert(1, "Sales");
printLine(userPlans.toJsonString());
//prints ["Marketing","Sales","Enterprise","Standard"]
last
Returns the last array element, same as [length() -1].
Declaration
{type} {instance}.last()
Examples
String[] userPlans;
userPlans.pushBack("Standard");
userPlans.pushBack("Sales");
String last = userPlans.last();
printLine(last);
//prints Sales
length
Returns the number of indexable elements.
Declaration
Integer {instance}.length()
Examples
String[] userPlans;
userPlans.pushBack("Standard");
userPlans.pushBack("Sales");
Integer arrLength = userPlans.length()
printLine("Array length: " + userPlans.length().toString());
//prints Array length: 2
popBack
Removes and returns the last element from the array.
Declaration
{type} {instance}.popBack()
Examples
String[4] userPlans;
userPlans[0] = "Standard";
userPlans[1] = "Marketing";
userPlans[2] = "Sales";
userPlans[3] = "Service";
String plan = userPlans.popBack();
printLine(plan);
//prints Service
popFront
Removes and returns the first element in the array.
Declaration
{type} {instance}.popFront()
Examples
String[4] userPlans;
userPlans[0] = "Standard";
userPlans[1] = "Marketing";
userPlans[2] = "Sales";
userPlans[3] = "Service";
String plan = userPlans.popFront();
printLine(plan);
//prints Standard
pushBack
Appends an empty element to the end of the array.
Declaration
Void {instance}.pushBack()
Examples
String[4] userPlans;
userPlans[0] = "Standard";
userPlans[1] = "Marketing";
userPlans[2] = "Sales";
userPlans[3] = "Service";
userPlans.pushBack();
printLine(userPlans.toJsonString());
//prints ["Standard","Marketing","Sales","Service",""]
pushBack({type})
Appends an element value to the end of the array.
Declaration
Void {instance}.pushBack({type} value)
Examples
String[4] userPlans;
userPlans[0] = "Standard";
userPlans[1] = "Marketing";
userPlans[2] = "Sales";
userPlans[3] = "Service";
userPlans.pushBack("Enterprise");
printLine(userPlans.toJsonString());
//prints ["Standard","Marketing","Sales","Service","Enterprise"]
pushFront
Adds an empty element of the correct type to the array.
Declaration
Void {instance}.pushFront()
Examples
String[4] userPlans;
userPlans[0] = "Standard";
userPlans[1] = "Marketing";
userPlans[2] = "Sales";
userPlans[3] = "Service";
userPlans.pushFront();
printLine(userPlans.toJsonString());
//prints ["","Standard","Marketing","Sales","Service"]
pushFront({type})
Adds a value to the beginning of an array.
Declaration
Void {instance}.pushFront({type} value)
Examples
String[4] userPlans;
userPlans[0] = "Standard";
userPlans[1] = "Marketing";
userPlans[2] = "Sales";
userPlans[3] = "Service";
userPlans.pushFront("Enterprise");printLine(userPlans.buildString(","));
//prints Enterprise,Standard,Marketing,Sales,Service
sort
This function will sort the array. It will only work on one-dimensional arrays. Arrays of basic types (Integer, String, Date, etc) will be sorted according to standard behavior. Arrays of complex types (SearchEngine, HTTP, etc) will not be sorted. Arrays of structs will be sorted if the struct has a function with the following signature: Boolean compare(sameStruct other).
Declaration
Void {instance}.sort()
Examples
Integer[] ints;
ints.pushBack(8);
ints.pushBack(2);
ints.pushBack(4);
ints.sort();
printLine(ints.buildString(","));
//prints 2,4,8
toJsonString
Returns a JSON formatted string of the array's contents. Same functionality as toJson(JSONBuilder), but doesn't require a JSONbuilder.
Declaration
String {instance}.toJsonString()
Examples
String[] strings;
strings.pushBack("Alpha");
strings.pushBack("Beta");
strings.pushBack("Charlie");
String json = strings.toJsonString();
//prints ["Alpha","Beta","Charlie"]