Basic lists
Lists in Gosu inherit from the Java interface java.util.List and
its common Java subclasses, such as java.util.ArrayList.
Creating a list
To create an empty list, you use generics notation to specify the type of
object that the list contains, such as in this
example of an ArrayList of
String objects:
var myemptylist = new ArrayList<String>()In many cases, you need to initialize the list with data. Gosu provides a natural syntax for initializing lists similar to initializing arrays.
For example, the following line is an array instantiation:
var s2 = new String[ ] {"This", "is", "a", "test."}In comparison, the following line instantiates a new ArrayList:
var strs = new ArrayList<String>(){"a", "ab", "abc"}The previous line is shorthand for the following code:
var strs = new ArrayList<String>()
strs.add("a")
strs.add("ab")
strs.add("abc")
See also
