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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started