Homework 15: Static Method Finger Exercises

Submit this homework using Gradescope. You can type up your answers, or write legibly and scan them. Do not attempt to submit a paper copy in class, as it will not be accepted.


(Some finger exercises, since we didn’t finish sorting Thursday. Remember, you can use Eclipse to check that you’re doing these right!)

A. (2 points) Suppose you have a List<E>. Write a generic static method deduplicate that modifies the list in-place, removing all but the first of any duplicated elements that the list contains, and leaving the list otherwise unchanged – specifically, do not change its order! Items are considered duplicates according to the semantics of their equals method.

For example, after deduplication, the list [3, 1, 2, 1, 3, 4] would be changed to [3, 1, 2, 4].

B. (2 points) Suppose you have a List<E>. Write a generic static method rotations that returns a Set<List<E>> consisting of the full set of unique rotations of its input. You can use Collections.rotate to rotate the input list. The input list should be unmodified after this method returns.

For example: