📜  在java代码示例中打印列表

📅  最后修改于: 2022-03-11 14:52:36.333000             🧑  作者: Mango

代码示例4
List numbers = Arrays.asList(1, 2, 3, 4, 5, 6);
//method 1 : Conventional way of printing arraylist
for (int number : numbers) {
    System.out.print(number+ ); //Output: 1 2 3 4 5 6
}

//method 2 : Lambda Expression to print arraylist
numbers.forEach(value -> System.out.print(value+ " ")); //Output: 1 2 3 4 5 6

//method 3 : Lambda Expression (method reference) to print arraylist
numbers.forEach(System.out::print); //Output: 123456