Question
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));
}
}
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));
}
}
Answer: Option C
Was this answer helpful ?
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 ?
More Questions on This Topic :
Question 3.
Which of these methods must be made static?
....
Submit Solution