InterviewSolution
| 1. |
What Is The Output Of This Program? 1. Import Java.util.*; 2. Class Arraylist { 3. Public Static Void Main(string Args[]) { 4. Arraylist Obj1 = New Arraylist(); 5. Arraylist Obj2 = New Arraylist(); 6. Obj1.add("a"); 7. Obj1.add("b"); 8. Obj2.add("a"); 9. Obj2.add(1, "b"); 10. System.out.println(obj1.equals(obj2)); 11. } 12. } |
|
Answer» 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 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 |
|