import java.util.Arrays;
import java.util.List;
public class StreamReduceDemo
{
public static void main(String[] args)
{
List<Integer> numberList = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9);
/*
* reduce processes all elements of the stream and produces a
* single result.
*/
numberList.stream().reduce((i1, i2) -> i1 > i2 ? i1 : i2)
.ifPresent(i -> System.out.println("max: " + i));
Integer total = numberList.stream().reduce(0,(i1, i2) -> i1 + i2);
System.out.println("total: " + total);
}
}
Outputmax: 9
total: 45
Click the below link to download the code:https://sites.google.com/site/ramj2eev1/home/javabasics/StreamDemo_Ter_Op_reduce_App.zip?attredirects=0&d=1Github Link:https://github.com/ramram43210/Java/tree/master/BasicJava/StreamDemo_Ter_Op_reduce_AppBitbucket Link:https://bitbucket.org/ramram43210/java/src/21c94b97f3d45cf2018afb81344804fbe9e1995b/BasicJava/StreamDemo_Ter_Op_reduce_App/?at=masterSee also: All JavaEE Viedos PlaylistAll JavaEE ViedosAll JAVA EE LinksServlets TutorialAll Design Patterns LinksJDBC TutorialJava Collection Framework TutorialJAVA TutorialKids Tutorial