Click here to watch in Youtube :
https://www.youtube.com/watch?v=LQX1Cl3ECrA&list=UUhwKlOVR041tngjerWxVccw
Click the below Image to Enlarge
How to use Method reference in forEach method of List | Method reference in Java 8 |
How to use Method reference in forEach method of List | Method reference in Java 8 |
How to use Method reference in forEach method of List | Method reference in Java 8 |
import java.util.ArrayList; import java.util.List; public class MethodReferenceDemo { public static void main(String[] args) { List<String> nameList = new ArrayList<>(); nameList.add("Peter"); nameList.add("John"); nameList.add("Juli"); nameList.add("Stephan"); nameList.forEach(name -> System.out.println(name)); System.out.println("------------------------"); // method reference nameList.forEach(System.out::println); } }Output
Peter John Juli Stephan ------------------------ Peter John Juli StephanClick the below link to download the code:
https://sites.google.com/site/ramj2eev1/home/javabasics/LambdaDemo_method_ref_list_foreach_app.zip?attredirects=0&d=1
Github Link:
https://github.com/ramram43210/Java/tree/master/BasicJava/LambdaDemo_method_ref_list_foreach_app
Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/769cad933ec9a28ea0eb78bc3917feeab1685676/BasicJava/LambdaDemo_method_ref_list_foreach_app/?at=master
See also:
No comments:
Post a Comment