Category: Tutorial

Java 8 Stream peek Sample

Java 8 Stream peek method will return a stream consisting of the elements of this stream, additionally performing the provided action on each element as elements are consumed from the resulting stream. The peek() method is an intermediate operation,

Java 8 Stream flatMap Sample

Java 8 Stream flatMap method will return a stream consisting of the results of replacing each element of this stream with the contents of a mapped stream produced by applying the provided mapping function to each element. In simpler

Java 8 Iterate Over HashMap

You have a few options in dealing with HashMap with the introduction of Java 8 Streams and Lambda Expressions. Prior to Java 8, iterating over HashMap was exclusively done with a for loop. The Stream.forEach() method has replaced that

Java 8 Stream toArray Sample

Java 8 Stream toArray method will return an array containing the elements of the Stream. Th Steam can be Integer, String, Char, or any other Java primitive data type. The Stream.toArray() has the following syntax: Object toArray() toArray() Stream

Java 8 Stream findAny Sample

Java 8 Stream findAny method, which is very intuitive, will find any element from a given Stream. To be used when you are looking for an element without concern for the encounter order. The behavior of findAny() is nondeterministic,

Java 8 Stream findFirst Sample

Java 8 Stream findFirst method is pretty straight forward in that it finds and returns the first element in the Stream. The Stream.findFirst() method states that if the stream has no encounter order, any element may be returned. The

Java 8 Stream filter Sample

Java 8 Streams filter method returns a stream consisting of the elements of this stream that match the given predicate. The Stream.filter() method will transform the data of one stream into another stream using whatever condition you have set.