2.5.  Develop code that uses the UnaryOperator interface


The java.util.function.UnaryOperator is a Java 8 functional interface that extends java.util.function.Function:

package java.util.function;

public interface UnaryOperator<T extends Object> extends Function<T, T> {




The UnaryOperator is used to work on a single operand and it returns the same type as an operand. UnaryOperator can be used as lambda expression to pass as an argument. While defining UnaryOperator, we need to define T apply(T t) method inherited from java.util.function.Function.

UnaryOperator<String> uo = s -> s + " is great !";
System.out.print(uo.apply("Java 8"));



Java 8 is great !

Professional hosting         Free 'Oracle Certified Expert Web Services Developer 6' Guide     Exam 1Z0-810: Upgrade to Java SE 8 Programmer Quiz