Example of a lambda expression reduce aggregation test in java1.8

Source: Internet
Author: User

 Public classLambdatest { Public Static voidMain (string[] args) {//equivalent to a foreach traversal operation result valueInteger out = Stream.of (5, 3, 2, 1, 0). Reduce (result, item) {            if(Item >= 3) {result= result +item; }            returnresult;        }). get ();        System.out.println (out); //equivalent to the given initial result value, the foreach traversal operation result valueThe Integer sum = Stream.of (5, 3, 2, 1, 0). Reduce (9, lambdatest::sumtest);        SYSTEM.OUT.PRINTLN (sum); //equivalent to a given initial result value, two foreach traversal operation result value        intstr = stream.of. Parallel (). Reduce (1, (result, item) {            returnResult +item; }, (result, item)- {            //Note: This method is only entered under parallel parallel            returnResult +item;        });    System.out.println (str); }    //Replace Integer::sum test     Public StaticInteger Sumtest (intA1,intA2) {        returnA1 +A2; }}

Example of a lambda expression reduce aggregation test in java1.8

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.