You can do it on one line using Java 8
Suppose you have this list of integers
List<Integer> lst = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8 ,9);
You can print all items in one shot this way
lst.forEach(nb -> System.out.print(nb + " "));
Or in this way
lst.forEach(System.out::print);
Result
1 2 3 4 5 6 7 8 9
Jad chahine
source share