SHARE
TWEET

Untitled

a guest Apr 20th, 2019 62 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 -> System.out.println(s));//same as:
  12.         list.forEach(s -> lamdaFu(s));//same as:
  13.         list.forEach(Main::lamdaFu);//same as:
  14.         list.forEach(lamdaExampleClass);
  15.     }
  16.  
  17.     private static void lamdaFu(String s) {
  18.         System.out.println(s);
  19.     }
  20.  
  21.     static class LamdaExampleClass implements Consumer<String>{
  22.  
  23.         @Override
  24.         public void accept(String s) {
  25.             System.out.println(s);
  26.         }
  27.     }
  28. }
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
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top