In an ArrayList, if an item is added using Insert method like below- al.Insert(2, "item") What will happen to the existing item at index 2?
Sandeep Soni
Select an image from your device to upload
It will shift to the next index of that ArrayList.
Please follow the given example below
ArrayList a1 = new ArrayList();a1.Add(“abc”);a1.Add(“aa”);a1.Add(“baba”);
//before inserting new elementConsole.WriteLine(a1[2]);
//adding new element at 2nd indexa1.Insert(2, “item”);
//after addedConsole.WriteLine(a1[2]);Console.WriteLine(a1[3]);//“baba” is shifted at index 3 now
Console.ReadLine();