Created
September 11, 2021 13:55
-
-
Save adityachaudhari/bbe42e343c00fc23c7f8da3f797643ac to your computer and use it in GitHub Desktop.
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
package com.java8.functionalinterfaces; | |
import java.util.function.UnaryOperator; | |
public class MethodReferenceJava8Example { | |
public static void main(String[] args) { | |
String testString1 = "THis is NEW TEst 1 StriNG"; | |
String testString2 = "THis is NEW TEst 2 StriNG"; | |
// UnartOperator is functional interface which accepts one argument and returns result with same argument type. | |
UnaryOperator<String> makeStringUpperCaseWithlambda = (s) -> s.toUpperCase(); | |
UnaryOperator<String> makeStringUpperCaseWithMethodReference = String::toUpperCase; | |
System.out.println("testString1 making it upper case with lambda function : "+makeStringUpperCaseWithlambda.apply(testString1)); | |
System.out.println("testString2 making it upper case with method reference : "+makeStringUpperCaseWithMethodReference.apply(testString2)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment