08: Working with Lists
Suppose we write lists by listing the values of the elements between curly braces (note: code below was corrected after the due date to show curly braces). For example, the list {1, 3, 5, 7}
represents a List
of Integer
s, containing the first four odd numbers.
Let odd = {1, 3, 5, 7}
and even = {8, 6, 4, 2}
.
Assume each of the following happens in sequence, that is, if odd
is modified in one question, carry that value forward into the next question.
(1 point each)
A. What is the contents of odd
if we call odd.addAll(even)
?
B. What is the contents of odd
if we then call odd.sort(null)
? (You may want to go look at the Java API here, but in short: it does what you’d expect.)
C. What is the contents of odd
if we then call odd.removeAll(even)
?
D. What is the contents of odd
if we then call odd.retainAll(even)
?