Java 8 | BiFunction | BiPredicate | BiConsumer

  • The lambda expression assigned to an object of BiFunction type is used to define its apply() which eventually applies the given function on the arguments.
R apply(T t, U u);
  • The main advantage of using a BiFunction is that it allows us to use 2 input arguments while in function we can only have 1 input argument.
@FunctionalInterface
public interface BiFunction<T, U, R>
  • T — Type of the first argument to the function.
  • U — Type of the second argument to the function.
  • R — Type of the result of the function.
  • 10. lines, we defined BiFunction with concat method.
  • 12.lines, we used apply method and put values.
  • 18.lines, we call powToString method, the method expects 2 integer values and a biFunction and a Function.
  • The method takes values and does Math.pow and then convert the result to String.
  • BiConsumers are useful when it is not required to return any value as they are expected to operate via side-effects.
  • We use accept method of BiConsumer
void accept(T t, U u)
  • BiConsumers is that it allows us to use 2 input arguments while in function don’t return any value
@FunctionalInterface
public interface BiConsumer<T, U>
  • T — Type of the first argument to the function.
  • U — Type of the second argument to the function.
  • 10. lines, we defined BiConsumer with map
  • 15–18.lines we put some values in map while we called putMap method
  • BiPredicate is a functional interface, which accepts two arguments and returns a boolean for the test
boolean test(T t, U u);
  • T — Type of the first argument to the function.
  • U — Type of the second argument to the function.
@FunctionalInterface
public interface BiPredicate<T, U> {
  • 7.lines we defined BiPredicate,
  • we put 2 arguments while called filterBiPredicate method and we used test(T t, U u) method,

Thank you for your time :)

Github: Binary

References:
BiFunction
BiConsumer
BiPredicate

--

--

--

Java Developer @XPoint-Tech

Love podcasts or audiobooks? Learn on the go with our new app.

Developer Analytics with Mixpanel

The cost of bad quality software

New Logo, Video as Background, Bulma framework, and Web Scraper in Node.js

Parallels For The Mac

My first Drupal 7 site

Software House Services and Structure

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Hasan Kadir Demircan

Hasan Kadir Demircan

Java Developer @XPoint-Tech

More from Medium

Datatypes in JVM

Introduction to Project Reactor in Java

Java record: A Brief

Easy way to set your Java Home