[go: up one dir, main page]

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

Tuesday, August 13, 2019

Java 8 IntPredicate Examples

1. Overview In this tutorial, We'll be learning the new java 8 IntPredicate functional Interface with examples. This is part of java.util.function package.

In the last article, We've seen an in-depth article on Predicate Function Interface in Java 8. This works exactly similar to the Predicate. Predicate works for all data types but IntPredicate works only for int values.


Short Introduction:

IntPredicate represents a predicate (boolean-valued function) of one int-valued argument. This is the int-consuming primitive type specialization of Predicate. IntPredicate interface has a functional method test() which takes int as an argument and returns a boolean value. This interface has only one abstract method hence it is called FI.

We will be seeing the syntax and its example programs on test(int value), and(IntPredicate other), negate() and or(IntPredicate other) methods.

test() is an abstract method and the remaining 3 are default methods.

In-depth Functional Interfaces (FI) in Java 8 with examples

1. Overview

In this tutorial, We'll learn about Functional Interface added to Java 8. Functional Interface is abbreviated as FI.

These Functional Interfaces are used extensively in Lambda Expressions.

Please read article on "A Complete Guide to Lambda Expressions"

If you have a basic understanding of Lambda's that will help in using Functional Interface(FI) properly. But, We will discuss in short about Lambda's.


We will cover the following concepts in this article.

  • Intro to Lambda
  • Lambda Examples
  • Functional Interface Definition
  • @FunctionalInterface annotation
  • Built-in FI's
  • Types of Functional Interfaces with examples


Monday, August 12, 2019

Java 8 Predicate Working Examples

1. Overview
In this tutorial, We'll learn how to work and use the Predicate Functional Interface.

In the previous post, We have discussed "Introduction to Functional Interfaces in Java 8". Explained an easy manner to understand the type of Functional Interfaces.

Predicate Functional interface is part of java.lang.function package.

Predicate is one of the categories of Function Interfaces (Suppliers, Consumers, Predicates and Function)

Below is the definition from Predicate API.

@FunctionalInterface
public interface Predicate<T>

Predicate has a abstract method named test(T t) which takes only one argument and does return a boolean value such as true or false.

This is mainly used to test a condition to perform certain operations.

test(T t) method can be called as Functional Method. Below is the signature.
boolean test(T t)

Predicate has many non-abstract methods apart from test(). Those are two static and three default methods.