我有一组值对象:
Set<EntityKey> clientAssignedPlaceholderEntityKeys
其中 EntityKey 类具有以下属性:
private Integer objectRef;
private String entityType;
使用流将不同的 objectRef 值提取到排序列表中的最有效方法是什么?
我有以下内容,但它两次调用 stream() 的事实似乎是一种难闻的气味:
// 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());
www说
函数式编程
MMTTMM
相关分类