1 public static void main(String[] args) { 2 // ‘代替匿名类’ 3 // new Thread(() -> System.out.println("java8 lambda")).start(); 4 5 // ‘list 遍历集合’ 6 List features = Arrays.asList("Lambdas", "Default Method", "Stream API", "Date and Time API"); 7 // features.forEach(n -> System.out.println(n)); 8 9 // ‘函数接口 filter’ 10 List languages = Arrays.asList("Java", "Scala", "C++", "Haskell", "Lisp"); 11 The predicateA <String> = the predicateA STR -> str.equals ( "the Java" ); 12 is // . Languages.stream () filter (n--> predicate.test ((String) n-)) forEach (n--> the System.. Out.println (n-)); 13 is // 'created by filtering a set of string string, variables need to find acceptance at 14 . List <string> tempString = (List <string>) languages.stream () filter (n- -> predicate.test ((String) n-)) the collect (Collectors.toList ());. 15 // tempString.forEach (the System.out :: the println); 16 // Map allows you change your internal elements . 17 List < Integer> = costBeforeTax Arrays.asList (100, 200 is, 300, 400, 500 ); 18 is // . costBeforeTax.stream () Map ((n-) -> + n-12 is n-*) .forEach (n--> System.out.println (n-)); . 19 // the reduce sql understood to be a function of 20 is Integer = costBeforeTax tempSum .stream () Map ((n-) -> + n-12 is n-*) .reduce ((sUM, N1) -> + sUM. N1) .get (); 21 is // summaryStatistics comprising Max Min, and the sum of the average the value 22 is IntSummaryStatistics = costBeforeTax.stream stats () mapToInt (N->. n-) .summaryStatistics (); 23 is System.out.println ( "Highest in Prime Number List:" + stats.getMax ()); 24 the System.out .println ( "Prime Number Lowest in List:" + stats.getMin ()); 25 System.out.println ( "the Sum of All Prime Numbers:" + stats.getSum()); 26 System.out.println("Average of all prime numbers : " + stats.getAverage()); 27 //function函数Function<T,R> 输入T返回R 28 Function<String,String> function = n-> n + "jack"; 29 System.out.println(function.apply("String")); 30 }