import java.util.ArrayList;
//创建一个集合,添加内容并遍历,规范打印格式:[元素一,元素二,元素三]
//集合中如果想添加基本数据类型要转换成包装类
public class Practice01 {
public static void main(String[] args) {
ArrayList<Integer> list=new ArrayList<>();
list.add(1);
list.add(2);
list.add(3);
list.add(4);
System.out.print("[");
for (int i = 0; i < list.size(); i++) {
if(i== list.size()-1){
System.out.print(list.get(i));
}else {
System.out.print(list.get(i)+", ");
}
}
System.out.print("]");
}
}
标签:遍历,ArrayList,list,System,print,add,集合,out
From: https://blog.51cto.com/u_16072958/8860880