[Java] Stream Sort

Sream<Employee> emps = ...;

emps.sorted(
    Comparator.comparingInt(Employee::getSalary)
                      .reversed()
    ).limit(10)
    .map(Employee::getName)
    .forEachOrdered(System.out::println);

 

ParalleSteam with unordered() to improve efficiency:

List<Integer> list = ...;

long n = list.parallelStream()
                  .unordered()
                  .distinct()
                   count();

 

posted @ 2021-01-18 22:43  Zhentiw  阅读(409)  评论(0编辑  收藏  举报