stream list into a set

后端 未结 1 1564
北海茫月
北海茫月 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 results = someDao.findByType(type)
            .stream()
            .map(ClassName::getValue)
            .collect(Collectors.toSet());
    

    0 讨论(0)
提交回复
热议问题