stream list into a set

后端 未结 1 1497
北海茫月
北海茫月 2021-01-01 09:13

I am looking to refactor how I have used a stream in some of my code. The first example is how I currently have done it. The second example is what im trying to make it lo

相关标签:
1条回答
  • 2021-01-01 09:21

    Use Collectors.toSet :

    Set<String> results = someDao.findByType(type)
            .stream()
            .map(ClassName::getValue)
            .collect(Collectors.toSet());
    
    0 讨论(0)
提交回复
热议问题