If I have an array and an array list:

int[] myArray = new int[2];
myArray[0] = 1;
myArray[1] = 2;

ArrayList myArrayList = new ArrayList();
myArrayList.Add("1st element");

By calling the Addrange() method in myArrayList, does this add the contents of myArray to the second element of myArrayList? If so how do you access the second element of myArray through myArrayList?

2 Years
Discussion Span
Last Post by iConqueror

The AddRange function simply adds all of the objects in the added range to the arraylist. In your example, your arraylist would contain three items accessible at positions 0, 1 and 2.
Think of it in terms as appending the array to the arraylist, it just gets tacked on the end.


Ok so now would my arraylist have the contents of at the following indexes:
[0] = "1st element"
[1] = 1 (1st element in array
[2] = 2 (2nd element in array)?


Exactly. It works like the zip or merge functions available in other languages, suching iterating throught the items in the object to be added and pushing them onto the add of the arraylist.
Auto increasing of the size of the arraylist is taken care of too so you don't need to worry about extending the arraylist past it initialised size before calling addRange.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.