1 import java.util.Arrays; 2 import java.util.List; 3 import java.util.function.IntBinaryOperator; 4 5 6 List<String> names = Arrays.asList("Alice", "Bob", "Charlie"); 7 8 // 方式一for输出 9 for (int i = 0; i < names.size(); i++) { 10 if(name.equals("Bob")){ 11 System.out.println("\"dier\" = " + "dier"); 12 } 13 14 // 方式二forEach输出 15 names.forEach(name -> 16 { 17 if(name.equals("Bob")){ 18 System.out.println("\"dier\" = " + "dier"); 19 } 20 }); 21 22 //补充,只执行一条语法 23 names.forEach(name -> System.out.println(name));
标签:Java,name,dier,System,lamad,names,java,forEach From: https://www.cnblogs.com/188221creat/p/18150034