Thursday, 15 June 2017

How to use Method reference in forEach method of List | Method reference in Java 8


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 
MethodReferenceDemo.java
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
Stephan
Click 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:

  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • All JAVA EE Links
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java Collection Framework Tutorial
  • JAVA Tutorial
  • Kids Tutorial
  • No comments:

    Post a Comment

    Google+ Followers

    Google+ Badge