Sail E0 Webinar
Question


What is the output of this program?


import java.util.*;
class Arraylist {
public static void main(String args[]) {
ArrayList obj1 = new ArrayList();
ArrayList obj2 = new ArrayList();
obj1.add("A");
obj1.add("B");
obj2.add("A");
obj2.add(1, "B");
System.out.println(obj1.equals(obj2));
}
}
Options:
A .  0
B .  1
C .  true
D .  false
Answer: Option C

obj1 and obj2 are an object of class ArrayList hence it is a dynamic array which can 

increase and decrease its size. obj.add("X") adds to the array element X and obj.add

(1,"X") adds element x  at index  position 1 in the list, Both the objects obj1 and obj2 

contain same elements i:e A & B thus obj1.equals(obj2) method returns true.

Output:
$ javac Arraylist.java
$ java Arraylist
true



Was this answer helpful ?
Next Question

Submit Solution

Your email address will not be published. Required fields are marked *

Latest Videos

Latest Test Papers