I have a set of value objects:
Set<EntityKey> clientAssignedPlaceholderEntityKeys
Where the EntityKey class has the following properties:
private Integer objectRef;
private String entityType;
What is the most efficient way to extract the distinct objectRef values into a sorted list using streams?
I have the following but the fact that it calls stream() twice seems like a bad smell:
// Extract into a sorted list all the distinct placeholder objectRefs (regardless of type).
List<Integer> sortedPlaceholderObjectRefs = clientAssignedPlaceholderEntityKeys.stream()
.map(entityKey -> entityKey.getObjectRef())
.collect(Collectors.toSet())
.stream() // having to call stream() a 2nd time here feels sub-optimal
.sorted()
.collect(Collectors.toList());