Introduction
Your goal in this lab is to complete the unfinished methods: CollectionExercises.java
The Gradescope JUnit tests are provided for your convenience: CollectionExercisesTest.java
For each method, you should first take a minute to think about the problem in order to select an appropriate collection type (or types) to use in your solution. The following documentation might be helpful.
You should take full advantage of the functionality provided by the collection classes to make your solutions as concise and efficient as possible. For example, the Collection
interface provides an addAll
method that makes it possible to add all of the elements of one collection to another using a single method call. Where appropriate, you should use that method rather than creating a loop that repeatedly calls the add
method.
Your solutions for these exercises must satisfy the following requirements:
- You may not use indexed for loops. Use only for-each loops or iterators, as appropriate.
- None of your methods may include nested loops. Nested loops generally take a long time to iterate over large collections. (You will look at this more formally in CS 240).
Submitting
Submit your completed file to Gradescope. You may submit as many times as you like.