For each question, make sure to show your work, i.e., how you come up with your
ID: 3917674 • Letter: F
Question
For each question, make sure to show your work, i.e., how you come up with your answers.
4. (10 pts) Suppose that list1 (ArrayList<Object>) is a list that contains the strings “red”, “yellow”, and “green”, and that list2 (ArrayList<String>) is another list that contains the strings “red”, “yellow”, and “blue”. Answer the following questions (All the questions are independent to each other):
What is list1 after executing list1.addAll(list2)?
What is list1 after executing list1.add(list2)?
What is list1 after executing list1.removeAll(list2)?
What is list1 after executing list1.remove(list2)?
What is list1 after executing list1.retainAll(list2)?
What is list1 after executing list1.clear()?
Explanation / Answer
list1.addAll(list2)
[red, yellow, green, red, yellow, blue]
list1.add(list2)
this line does not compile
list1.removeAll(list2)
[green]
list1.remove(list2)
this line does not compile
list1.retainAll(list2)
[red,yellow]
list1.clear()
[]
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.