What is the default Set/List implementation with Collectors in Java 8 Stream API?

前端 未结 1 1323
北荒
北荒 2021-01-07 04:00

I have below code snap with Java 8.

 List employees = DataProvider.getEmployees();
 Set set = employees.stream().filter(         


        
相关标签:
1条回答
  • 2021-01-07 04:52

    The toSet() collector does not specify which implementation it uses; you get a Set, that's all.

    If you want a specific kind of set, use toCollection() and provide a factory method for your set:

        ...collect(Collectors.toCollection(HashSet::new));
    
    0 讨论(0)
提交回复
热议问题