Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shyamramineni/e9442a380ebdc1400267f0889c81e00d to your computer and use it in GitHub Desktop.
Save shyamramineni/e9442a380ebdc1400267f0889c81e00d to your computer and use it in GitHub Desktop.
Functional Interface Examples
import java.util.function.*;
public class FunctionalInterfaces {
public static void main(String args[]) {
Predicate<String> lengGtTen = (s) -> s.length() > 0;
System.out.println(lengGtTen.test("20"));
Consumer<String> lowerCaseConsumer = (str) -> System.out.println(str.toLowerCase());
lowerCaseConsumer.accept("ABCD");
Function<Integer,String> intToStr = (num) -> Integer.toString(num);
System.out.println(intToStr.apply(10).length());
Supplier<String> s = () -> "Back to learning Java";
System.out.println(s.get());
BinaryOperator<Integer> addTwo = (a,b) -> a + b +10;
System.out.println(addTwo.apply(10,20));
UnaryOperator<Integer> addTen = (num) -> num + 10;
System.out.println(addTen.apply(10));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment