In Java programs, we normally use System.out.println() to print values of an Object we want to see. But with Streams, the intermediate operations don’t run until needed. So, its a little trickier.. Here are some approaches we can use to print the stream contents. Using forEach Stream<String> streamCountries = Stream.of("Germany", "England", "China", "Denmark", "Brazil"); …
Continue reading Printing elements of a Stream in Java 8Streams
Parallel Streams A serial stream processes elements in an ordered manner, one at a time. A parallel stream uses multiple threads to process data concurrently. By default, the no of available CPUs affects the no of threads available for parallel stream. Creating Parallel Streams Using parallel() to create parallel stream from existing stream : …
Continue reading Java 8 Parallel StreamsIntStream is a specialized Stream for manipulating int values. In this article, we will see some examples of IntStream operations. Creating an IntStream IntStream static method of() accepts an int array as argument and returns an IntStream. int[] numbers = { 2, 4, 1, 7, 5, 10, 3 }; IntStream intStream = IntStream.of(numbers); …
Continue reading Java 8 IntStream operations with examplesJava 8 Stream class provides methods min() and max() for finding minimum and maximum values in a stream. Java 8 also added a static method comparing() to the Comparator class that lets us build a comparator using a sort key. Lets see some examples of Stream min() and max() functions with the Comparator.comparing() method. …
Continue reading Finding min and max of Stream using min(), max() functions in Java 8