我希望重新设计我在代码中使用流的方式。第一个例子是我目前使用的方式,第二个例子是我试图让它看起来像什么。
Set<String> results = new HashSet<String>();
someDao.findByType(type)
.stream()
.forEach(t-> result.add(t.getSomeMethodValue()) );
它可能看起来像这样吗?如果是,我该如何让它做到呢?
Set<String> results = someDao.findByType(type)
.stream()
.collect( /* ?? no sure what to put here */ );
someDao.findByType(type) .stream().map(TheClass::getValue).collect(toSet());
- Alexis C.