Related questions with answers
Question
Show the output of the following code:
ArrayList<String> list = new ArrayList<>();
list.add("New York");
ArrayList<String> list1 = list;
ArrayList<String> list2 = (ArrayList<String>)(list.clone());
list.add("Atlanta");
System.out.println(list == list1);
System.out.println(list == list2);
System.out.println("list is " + list);
System.out.println("list1 is " + list1);
System.out.println("list2.get(0) is " + list2.get(0));
System.out.println("list2.size() is " + list2.size());
Solution
VerifiedAnswered 2 years ago
Answered 2 years ago
The output of the given code is
true
false
list is [New York, Atlanta]
list1 is [New York, Atlanta]
list2.get(0) is New York
list2.size() is 1
Create a free account to view solutions
By signing up, you accept Quizlet's Terms of Service and Privacy Policy
Create a free account to view solutions
By signing up, you accept Quizlet's Terms of Service and Privacy Policy
Recommended textbook solutions

Computer Organization and Design MIPS Edition: The Hardware/Software Interface
5th Edition•ISBN: 9780124077263 (6 more)David A. Patterson, John L. Hennessy226 solutions

Intro to Java Programming, Comprehensive Version
10th Edition•ISBN: 9780133761313 (5 more)Y. Daniel Liang1,627 solutions

Fundamentals of Database Systems
7th Edition•ISBN: 9780133970777Ramez Elmasri, Shamkant B. Navathe948 solutions

Introduction to Algorithms
3rd Edition•ISBN: 9780262033848 (3 more)Charles E. Leiserson, Clifford Stein, Ronald L. Rivest, Thomas H. Cormen872 solutions
More related questions
1/4
1/7