Because list are linked list, the objects are joined by nodes so there isnt an easy command to get the object at a set point. But you can do stuff like this:
Strict
Import mojo
Global list:List<Int> = New List<Int>
Function Main:Int()
list.AddLast(10)
list.AddLast(20)
list.AddLast(30)
Print "Everything in the list:"
For Local i:Int = Eachin list
Print i
Next
Print ""
Print "Whats the second on in the list?"
Print GetObjectAt(1) ' 0 based!
Print ""
Print "Let's convert the list into an array..."
Local arr:=list.ToArray()
Print arr[1]
Return 0
End
Function GetObjectAt:Int(index:Int)
Local counter:Int = 0
For Local i:Int = Eachin list
If counter = index
Return i
End
counter+=1
Next
Return 0
End
Another option is to try Diddy's ArrayList where it is indexed ;)
|