Created
April 21, 2020 09:20
-
-
Save shyamramineni/e9442a380ebdc1400267f0889c81e00d to your computer and use it in GitHub Desktop.
Functional Interface Examples
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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