-
What is the output of this program?
import java.util.*;
public class Arraylist_Example
{
public static void main(String args[])
{
ArrayList object = new ArrayList();
object.add("L");
object.add("V");
object.add("E");
object.add(1, "O");
System.out.println(object);
}
}
-
- [L, O]
- [O]
- [L, O, V, E]
- [L, O, V]
- None of these
Correct Option: C
object is an object of class ArrayList hence it is an dynamic array which can increase and decrease its size. object.add(“n”) adds to the array element n and object.add(1,”n”) adds element n at index position 1 in the list, Hence object.add(1,”O”) stores O at index position 1 of obj and shifts the previous value stored at that position by 1.