文章目录  Lambda 表达式的常见用法 使用Lambda表达式集合遍历 使用Lambda表达式排序 使用Lambda表达式过滤 使用Lambda表达式映射 使用Lambda表达式归约 使用Lambda表达式分组 使用Lambda表达式函数式接口的实现 使用Lambda表达式线程的创建 使用Lambda表达式进行Optional 操作 使用Lambda表达式进行Stream的流操作   
 
List < String > =  Arrays . asList ( "apple" , "banana" , "orange" , "mango" , "grape" ) ; 
for  ( String  s :  fruitList)  { System . out. println ( s) ; 
} 
fruitList. forEach ( System . out:: println ) ; 
        List < String > =  Arrays . asList ( "apple" , "banana" , "orange" , "mango" , "grape" ) ; Collections . sort ( fruitList,  new  Comparator < String > ( )  { @Override public  int  compare ( String  o1,  String  o2)  { return  o1. compareTo ( o2) ; } } ) ; Collections . sort ( fruitList,  ( ( o1,  o2)  ->  o1. compareTo ( o2) ) ) ; 
        List < String > =  Arrays . asList ( "apple" , "banana" , "orange" , "mango" , "grape" ) ; List < String > =  new  ArrayList < > ( ) ; for  ( String  s :  fruitList)  { if  ( s. startsWith ( "a" ) )  { list1. add ( s) ; } } List < String > =  fruitList. stream ( ) . filter ( s ->  s. startsWith ( "a" ) ) . collect ( Collectors . toList ( ) ) ; 
        List < String > =  Arrays . asList ( "apple" , "banana" , "orange" , "mango" , "grape" ) ; List < Integer > =  new  ArrayList < > ( ) ; for  ( String  s :  fruitList)  { list1. add ( s. length ( ) ) ; } List < Integer > =  fruitList. stream ( ) . map ( s ->  s. length ( ) ) . collect ( Collectors . toList ( ) ) ; 
        List < Integer > =  Arrays . asList ( 1 , 2 , 3 , 4 , 5 , 6 , 8 ) ; int  sum1 =  0 ; for  ( Integer  v :  sumList)  { sum1 +=  v; } Integer  sum2 =  sumList. stream ( ) . reduce ( 0 ,  ( a,  b)  ->  a +  b) ; 
        List < String > =  Arrays . asList ( "apple" , "banana" , "orange" , "mango" , "grape" ) ; Map < Integer ,  List < String > > =  new  HashMap < > ( ) ; for  ( String  s :  fruitList)  { if  ( ! group1. containsKey ( s. length ( ) ) ) { group1. put ( s. length ( ) ,  new  ArrayList < > ( ) ) ; } group1. get ( s. length ( ) ) . add ( s) ; } Map < Integer ,  List < String > > =  fruitList. stream ( ) . collect ( Collectors . groupingBy ( String :: length ) ) ; 
        interface  MyInterface  { public  void  doSomething ( String  s) ; } MyInterface  myInterface1 =  new  MyInterface ( )  { @Override public  void  doSomething ( String  s)  { System . out. println ( s) ; } } ; MyInterface  myInterface2 =  ( s)  ->  System . out. println ( s) ; MyInterface  myInterface3 =  System . out:: println ; 
        Thread  thread =  new  Thread ( new  Runnable ( )  { @Override public  void  run ( )  { System . out. println ( "Hello World" ) ; } } ) ; thread. start ( ) ; Thread  thread1 =  new  Thread ( ( )  ->  System . out. println ( "Hello World" ) ) ; Thread  thread2 =  new  Thread ( System . out:: println ) ; Thread  thread3 =  new  Thread ( LambdaUsefullness :: listreduceSum ) ; 
ThreadPoolExecutor  executor =  new  ThreadPoolExecutor ( 2 ,  5 ,  2L ,  TimeUnit . SECONDS ,  new  LinkedBlockingDeque < > ( 4 ) ,  Executors . defaultThreadFactory ( ) ,  new  ThreadPoolExecutor. AbortPolicy ( ) ) ; executor. execute ( ( )  -> { for  ( int  i =  0 ;  i <  10  ;  i++ )  { System . out. println ( "Hello World分支线程====" + i) ; } } ) ; 
        String  str =  "Hello world" ; if  ( ! str. isEmpty ( ) )  { System . out. println ( str. toUpperCase ( ) ) ; } Optional . ofNullable ( str) . map ( String :: toUpperCase ) . ifPresent ( System . out:: println ) ; 
        List < String > =  Arrays . asList ( "apple" , "banana" , "orange" , "mango" , "grape" ) ; List  list1 =  new  ArrayList ( ) ; for  ( String  s :  fruitList)  { if  ( s. contains ( "n" ) )  { list1. add ( s. toUpperCase ( ) ) ; } } Collections . sort ( list1) ; List < String > =  fruitList. stream ( ) . filter ( s ->  s. contains ( "n" ) ) . map ( String :: toUpperCase ) . sorted ( ) . collect ( Collectors . toList ( ) ) ;