In Guava:
Set<Integer> subset = ImmutableSet.copyOf(Iterables.limit(set, 20));
Note that Iterables.limit() is evaluated lazily, so only one extra collection is created.
In Guava:
Set<Integer> subset = ImmutableSet.copyOf(Iterables.limit(set, 20));
Note that Iterables.limit() is evaluated lazily, so only one extra collection is created.