Question

For an assignment I have to write a method which combines a number of sets into one set and returns it.

This is easy enough, but the interface specifies that the returned set should be backed by the group of sets, that is to say that making a change to one of the subsets affects the overset.

By creating a Set and using .addAll() on each of the subsets, will this result in the desired behavior? The Javadoc doesn't say if it's a shallow or deep copy.

Was it helpful?

Solution

For anyone else who finds this question, the answer is no, changing the subsets does not affect the superset if you've used .addAll() from the standard library.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top