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