Description |
The Value object is inserted into the ArrayList at the given (0 based) Index position.
The element Count is incremented by 1. The Capacity is doubled if exceeded.
The Index value is allowed to equal but not exceed the Count value - whence it is added to the end of the list.
|
| Notes | An exception is thrown if the Index exceeds the Count value.
|
|
Microsoft MSDN Links |
System.Collections
System.Collections.ArrayList
|
|
|
A simple example |
program Project1;
{$APPTYPE CONSOLE}
uses
System.Collections;
var
List : System.Collections.ArrayList;
i : Integer;
begin
// Create our array list object
List := ArrayList.Create;
// Fill it with strings
List.Add('Hello');
List.Add('cruel');
List.Add('World');
// Display the contents : note the 0 indexing
for i := 0 to List.Count-1 do
Console.WriteLine(List.Item[i]);
// Insert a new element
Console.WriteLine;
List.Insert(1, 'very');
// Display the contents : note the 0 indexing
for i := 0 to List.Count-1 do
Console.WriteLine(List.Item[i]);
Console.Readline;
end.
| Show full unit code | Hello
cruel
World
Hello
very
cruel
World
|
|
|
|