Java Lambda - LongUnaryOperator andThen example








LongUnaryOperator andThen returns a composed operator that first applies this operator to its input, and then applies the after operator to the result.

Syntax

andThen has the following syntax.

default LongUnaryOperator andThen(LongUnaryOperator after)

Example

The following example shows how to use andThen.

import java.util.function.LongUnaryOperator;
//  w w  w .  j a va2s  .c o  m
public class Main {

  public static void main(String[] args) {
    LongUnaryOperator i = (l) -> -l;
    
    LongUnaryOperator j = (l) -> l/2;
    
    System.out.println(i.andThen(j).applyAsLong(Long.MAX_VALUE));
  }
}

The code above generates the following result.