Home » JAVA Programming » Arrays » Question
  1. What is the output of this program?
    import java.util.*;
    public class ArraylistExample
    {
    public static void main(String args[])
    {
    ArrayList object0 = new ArrayList();
    ArrayList object1 = new ArrayList();
    object0.add("I");
    object0.add("P");
    object1.add("I");
    object1.add(1, "P");
    System.out.println(object0.equals(object1));
    }
    }
    1. I
    2. P
    3. L
    4. False
    5. True
Correct Option: E

object0 and object1 are an object of class ArrayList hence it is a 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, Both the objects object0 and object1 contain same elements i:e I & P thus object0.equals(object1) method returns false.



Your comments will be displayed only after manual approval.