Prev | Current Page 119 | Next

L. McColl-Sylvester and F. Ponticelli

"Professional haXe and Neko"

As indexing is not supported, one
cannot simply pass a value to a new index. To alleviate this difference, the List type provides an add
method that facilitates adding a value to the next available index in a similar fashion to the Arrays
push method. The differences between the two are that the add method returns Void instead of the
index id where the data was added:
var myList : List < Int > = new List();
myList.add(someValue);
You can also add a value to the beginning of a List , using the push method. However, this is where
things start to get pretty confusing, as it bears the same name as the push method used for adding a
value to the end of an Array.
myList.push(someValue);
As with Arrays, the push method also has a paired pop method, which removes and returns the item at
the beginning of the List :
var poppedValue : Int = myList.pop();
Unlike the Array, the List has no method to directly remove the item stored at the end of the List .
Querying Values in a List
As noted earlier, List s do not support indexes, so you cannot directly access an item within the List .


Pages:
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131