如何以多行而不是一长列打印arraylist

时间:2019-03-11 09:15:44

标签: java

//I have written this method but I don't know how to proceed. 

public static void print(ArrayList<Integer> list) {
    for (int i=0;i<list.size();i++) {
        System.out.print(list.get(i));

1 个答案:

答案 0 :(得分:2)

使用

System.out.println(list.get(i));

代替

System.out.print(list.get(i));

println方法在打印后添加换行符。