zoukankan      html  css  js  c++  java
  • java8求和

    /**
    * 五种求和方式
    */
    @Test
    public void demo3(){
    List<Person> personlist = new ArrayList<>();
    Person person = new Person();
    for(int i=0;i<10;i++){
    person.setId(i);
    person.setName("你好=="+i);
    personlist.add(person);
    }
    Long firstSum = personlist.stream()
    .collect(Collectors.summarizingLong(Person::getId)).getSum();
    Long secondSum = personlist.stream()
    .collect(Collectors.summingLong(Person::getId));
    int thirdSum = personlist.stream()
    .mapToInt(Person::getId).sum();
    Integer forthSum = personlist.stream()
    .collect(Collectors.reducing(0,Person::getId,(i,j)->i+j));

    IntSummaryStatistics stats = personlist.stream().mapToInt(Person::getId).summaryStatistics();
    Long fiveSum = stats.getSum();
    System.out.println(firstSum + ":" + secondSum + ":" + thirdSum + ":" + forthSum + ":" + fiveSum);

    }

  • 相关阅读:
    qsort
    strcmp
    LotteryDrawing
    retire or not retire ? is a question.
    alloc && afree
    strlen
    c point
    c point ccccc
    MySQL MGR源码分析2
    MySQL MGR实现分析
  • 原文地址:https://www.cnblogs.com/beipiaoyizu/p/13857653.html
Copyright © 2011-2022 走看看