Question: Collections 4a) List the three key differences between arrays and ArrayLists in Java. 4b) Consider a class with a field variable xs declared by ArrayList
Collections
4a) List the three key differences between arrays and ArrayLists in Java.
4b) Consider a class with a field variable xs declared by
ArrayList
Write method alternating that removes alternating elements from xs.
For example, if xs is <"A", "B", "C", "D", "E">,
after alternating has run, xs will be {"A", "C", "E"}.
Similarly, if xs is <"A", "B", "C", "D", "E", "F">,
after alternating has run, xs will be {"A", "C", "E"}.
// removes alternating elements from the field variable xs
public void alternating()
4c) Describe how alternating would have to be written if xs were an array
variable instead of an ArrayList. What issues might this cause?
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
