We might write lists as a sequence of values between square braces. For example, the list ["apple", "banana", "cherry", "peach"]
represents a List
of String
s, containing the names of four fruits.
Let fruits = ["orange","apple","peach","banana"]
and vegetables = ["spinach","broccoli","okra","lettuce"]
.
You will probably need to look over the Java List
API to complete this assignment.
(1 point each)
A. Write a single statement which adds all of the items in fruits
, in order, to the end of vegetables
.
B. Write a single statement which removes all of the items in fruits
from the vegetables
list.
C. What is the contents of fruits
if we call fruits.sort(null)
?
D. Will the contents of fruits
be sorted by alphabetically, by Unicode value, or by the length of the strings? (Hint: look at the relevant compareTo()
method’s documentation.)