Showing posts with label java.util.stream. Show all posts
Showing posts with label java.util.stream. Show all posts

Tuesday, August 20, 2019

Java 8 Streams filter() - Working Examples

1. Overview


In this tutorial, We'll learn about the new Java 8 Streams API filter() method. This filter method is the one mostly used in streams. Streams build the operations sequentially and parallel.

filter() method takes Predicate which holds a condition. If the condition is true then this element is passed to the next operation in the stream.


We will discuss with example programs so that you can understand clearly.

First, will talk about syntax, examples and how it works internally.

Friday, August 16, 2019

Java 8 StreamSupport Examples

1. Overview


In this tutorial, We'll be learning Java 8 StreamSupport class methods with example programs. Let us see its syntax and how to convert iterable to Stream using StreamSupport.stream() method. This class is part of java.util.stream package.

Core methods of StreamSupport class are stream(), intStream(), doubleStream(), longStream().

Wednesday, August 14, 2019

Java 8 - 13 Stream Terminal Operations With Examples

1. Overview


In this tutorial, We'll learn What are Terminal Operations in Java 8. List all Java 8 Stream Terminal Operations with Examples.

Java-8 Stream terminal operations produce a non-stream, results such as primitive value, a collection or no value at all. Terminal operations are typically preceded by intermediate operations that return another Stream which allows operations to be connected in a form of a query.

or

Terminal operations can be performed on Stream directly.
Whereas Stream Intermediate operations produce a stream as a result.


Monday, August 12, 2019

Java 8 IntStream anyMatch() Method Example

1. Overview


In this example tutorial, We'll be learning Java 8 IntStream API anyMatch() method to verify Predicate condition matches to any values in the IntStream.

In the last tutorial, We've seen how to check whether all elements are matched to predicate condition using allmatch() method.

Let us see anyMatch() syntax, Example programs on this method.

API Note:

Returns whether any elements of this stream match the provided predicate. May not evaluate the predicate on all elements if not necessary for determining the result. If the stream is empty then false is returned and the predicate is not evaluated.

Java 8 IntStream allMatch() Method Example

1. Overview


In this article, We'll be learning a new java 8 API IntStream allMatch() method. This is very useful to match a condition to all of the IntStream values.

As we know, IntStream accepts only integer values (This is designed for only integer values to improve performance and avoid errors). Performance is enhanced by avoiding the type casting in case of String has only numbers.

API Note:

Returns whether all elements of this stream match the provided predicate. May not evaluate the predicate on all elements if not necessary for determining the result. If the stream is empty then true is returned and the predicate is not evaluated.

we have already seen a similar method allMatch() in Stream API.

Sunday, August 11, 2019

Java 8 IntStream boxed() Method Example

1. Overview

In this tutorial, We'll learn about the new java 8 IntStream API boxed() method.

IntStream boxed() returns a Stream consisting of the elements of this stream, each boxed to an Integer. That means to convert all primitive int values to wrapper Integer type objects Stream.

This is part of Java.util.IntStream API course.

Note: This method is part of Intermediate Operations. All these are invoked lazy and executed upon terminal operations invocation.

Terminal opeartions such as forEach(), forEachOrdered(), iterator() etc.

Saturday, August 10, 2019

Java 8 IntStream findFirst() Method Example

1. Overview

In this tutorial, We'll learn Java 8 IntStream API findFirst() method usage along with example programs. IntStream is part of java.util package.

We've already seen many methods of IntStream API.

This is used to get the first element from the stream. In this article, We will see its syntax, example program, and internal implementation.

API Note:

Returns an OptionalInt describing the first element of this stream, or an empty OptionalInt if the stream is empty. If the stream has no encounter order, then any element may be returned.

Saturday, July 27, 2019

Java 8 IntStream empty() Method Example

1. Introduction


In this tutorial, We'll learn about Java 8 Instream API empty() method example programs.

empty() method is used to create a new empty Instream. The returned stream is a sequential stream. That means all the elements of Stream are processed one by one the order they appear in it.



Java8_IntStream_empty