Accessing elements of a Gosu array

In Gosu, you access elements of an array with array index notation. Place the index value for the element you want to access within square brackets that follow the array name. Index values for array elements begin with zero and increment by one. The following code uses the index value 2 to access the third element of an array.

// Create an array with four elements.
var stringArray = new String[] {"one", "two", "three", "four"} 

// Print the the third element of the array. 
print ("Third array element contains the value " + stringArray[2] + ".")

The output from this code is:

The third array element contains the value three. 

Examples

The following code accesses the first exposure on a claim.

Claim.Exposures[0] 

The following code creates an array of five elements and then accesses the third element, the character “c”.

gw.api.util.StringUtil.splitWhitespace( "a b c d e" )[2]