I think you need to rethink your requirements. You need a set of squares. Why?
Many give you uniqueness and iteration, nothing more. You are unique in Iterable, because the source is a collection, and you can iterate over elements in Iterable. So why do you need a kit?
There are only two possible reasons: either you are working with an API that needs the Set (or Collection) parameter, or you need to somehow display the size of the Set.
In these cases, use Sets.newHashSet(iterable)
to create a set (on the one hand, of course, which requires a full iteration, on the other hand: you will need a full iteration at any time when you repeat the values, so why not do it now ?). Otherwise, just use Iterable and forget about the set.
source share