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 xs;

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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!