Professional Documents
Culture Documents
Int y=x[2][2]
System.Array class - to manipulate arrays more efficiently
System.Array class - to manipulate arrays more efficiently
ArrayList class - to manipulate arrays more efficiently
• System.Collections namespace defines a class known as ArrayList that
can store a dynamically sized array of objects.
• The ArrayList class includes a number of methods to support
operations such as sorting, removing and enumerating its contents.
• It also supports a property Count that gives the number of objects in
an arraylist and a property Capacity to modify or read the capacity.
• An array list is very similar to an array, except that it has the ability to
grow dynamically.
• We can create an array list by indicating the initial capacity we want
ArrayList class - to manipulate arrays more efficiently
ArrayList cities = new ArrayList (30);
• It creates cities with a capacity to store thirty objects. If we do not specify the size, it defaults
to sixteen.
ArrayList cities = new ArrayList ( ); will create a cities list with the capacity to store sixteen
objects.
We can add elements to the list using the Add ( ) method:
cities.Add (“Bombay”);
cities.Add (“Anand”);
• We can also remove an element: cities.RemoveAt (1); This will remove the object in position1.
• We can modify the capacity of the list using the property Capacity: cities.Capacity = 20;
• We may obtain the actual number of objects present in the list using the property Count as
follows:
int n = cities.Count;
ArrayList class - to manipulate arrays more efficiently
ArrayList class - to manipulate arrays more efficiently