SHARE
TWEET

Untitled

a guest Apr 20th, 2019 91 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.Arrays;
  2. import java.util.List;
  3. import java.util.function.Consumer;
  4.  
  5. public class Main {
  6.  
  7.     private static LamdaExampleClass lamdaExampleClass = new LamdaExampleClass();
  8.  
  9.     public static void main(String[] args) {
  10.         List<String> list = Arrays.asList("elem1","elem2");
  11.         list.forEach(s -> lamdaFu(s));//same as:
  12.         list.forEach(Main::lamdaFu);//same as
  13.         list.forEach(lamdaExampleClass);
  14.     }
  15.  
  16.     private static void lamdaFu(String s) {
  17.         System.out.println(s);
  18.     }
  19.  
  20.     static class LamdaExampleClass implements Consumer<String>{
  21.  
  22.         @Override
  23.         public void accept(String s) {
  24.             System.out.println(s);
  25.         }
  26.     }
  27. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top