Use a functional interface from the java.util.function package to implement a lambda expression - Java Lambda Stream

Java examples for Lambda Stream:Lambda

Description

Use a functional interface from the java.util.function package to implement a lambda expression

Demo Code

import java.util.function.Function;

public class Main {

  public static void main(String[] args) {

    Function<String, String> newText2 = (testText) -> {
      String tempStr = "";
      for (String part : testText.split(" ")) {
        tempStr += new StringBuilder(part).reverse().toString() + " ";
      }//  w  w  w .j  a v  a 2  s  . co m
      return tempStr;
    };
    System.out.println(newText2.apply("HELLO WORLD"));
  }
}

Result

Functional Interfaces Contained in java.util.function

Interface Implementation Description
BiConsumer<T,U> Function that accepts two input arguments and returns no result.
BiFunction<T,U,R> Function that accepts two arguments and produces a result.
BinaryOperator<T> Function on two operands of the same type, producing a result of the same type as the operands.
BiPredicate<T,U> Predicate of two arguments. Returns a Boolean value.
BooleanSupplier Supplier of Boolean-valued results.
Consumer<T> Function that accepts a single input argument and returns no result.
DoubleBinaryOperator Function upon two double-valued operands and producing a double-valued result.
DoubleConsumerFunction that accepts a single double-valued argument and returns no result.
DoubleFunction<R> Function that accepts a double-valued argument and produces a result.
DoublePredicate Predicate of one double-valued argument.
DoubleSupplierSupplier of double-valued results.
DoubleToIntFunction Function that accepts a double-valued argument and produces an int-valued result.
DoubleToLongFunction Function that accepts a double-valued argument and produces a long-valued result.
DoubleUnaryOperator Function on a single double-valued operand that produces a double-valued result.
Function<T,R> Function that accepts one argument and produces a result.
IntBinaryOperator Function upon two int-valued operands and producing an int-valued result.
IntConsumer Function that accepts a single int-valued argument and returns no result.
IntFunction<R>Function that accepts an int-valued argument and produces a result.
IntPredicate Predicate of one int-valued argument.
IntSupplier Supplier of int-valued results.
IntToDoubleFunction Function that accepts an int-valued argument and produces a double-valued result.
IntToLongFunction Function that accepts an int-valued argument and produces a long-valued result.
IntUnaryOperator Function on a single int-valued operand that produces an int-valued result.
LongBinaryOperatorFunction upon two long-valued operands and producing a long-valued result.
LongConsumer Function that accepts a single long-valued argument and returns no result.
LongFunction<R> Function that accepts a long-valued argument and produces a result.
LongPredicate Predicate of one long-valued argument.
LongSupplier Supplier of long-valued results.
LongToDoubleFunction Function that accepts a long-valued argument and produces a double-valued result.
LongToIntFunction Function that accepts a long-valued argument and produces an int-valued result.
LongUnaryOperator Function on a single long-valued operand that produces a long-valued result.
ObjDoubleConsumer<T> Function that accepts an object-valued and a double-valued argument and returns no result.
ObjIntConsumer<T> Function that accepts an object-valued and an int-valued argument and returns no result.
ObjLongConsumer<T>Function that accepts an object-valued and a long-valued argument and returns no result.
Predicate<T> Predicate of one argument.
Supplier<T> Supplier of results.
ToDoubleBiFunction<T,U> Function that accepts two arguments and produces a double-valued result.
ToDoubleFunction<T> Function that produces a double-valued result.
ToIntBiFunction<T,U> Function that accepts two arguments and produces an int-valued result.
ToIntFunction<T> Function that produces an int-valued result.
ToLongBiFunction<T,U> Function that accepts two arguments and produces a long-valued result.
ToLongFunction<T> Function that produces a long-valued result.
UnaryOperator<T> Function on a single operand that produces a result of the same type as its operand.

Related Tutorials