List of Only One Single value of Filtered List Value

假如想象 提交于 2019-12-06 03:09:07

You just want distinct values, for that you have to use a Set. Here's how it looks.

Set<Integer> typeList = listCompetitors.stream()
    .map(Competitor::getType)
    .collect(Collectors.toSet());

Based on the answer of Ravindra

// List with only types
List<Integer> typeList = new ArrayList<>(listCompetitors.stream()
    .map(Competitor::getType)
    .collect(Collectors.toSet()));

typeList.stream().forEach(System.out::println);

The output

1
2
3
4
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!