Java中Lambda表达式的使用

语法格式:(parameters) -> expression 或 (parameters) ->{ statements; }

创建一个String类型的数组

static String[] atp = {"11", "22","33", "44", "55", "66"};

用Arrays的asList方法将其转换为List集合

 

static List<String> players = Arrays.asList( atp );

//以前使用超级for循环遍历集合

public static void main(String[] args) {

for (String player : players) {

System.out.print( player + "; " );

}

//使用 lambda 表达式以及函数操作(functional operation)

//players.forEach((player) -> System.out.print(player + "; "));

posted @ 2018-08-14 08:52  锋_锋  阅读(128)  评论(0编辑  收藏  举报