我这里有一个数组列表:
public static void main(String[] args) {
Person P1 = new Person("Nathen", 144.5, 55.1);
Person P2 = new Person("Jamie", 133, 60);
Person P3 = new Person("Tom", 134, 65);
Person P4 = new Person("Lavi", 170, 70);
ArrayList<String> Person = new ArrayList<String>();{
Person.add(P1.getCategory());
Person.add(P2.getCategory());
Person.add(P3.getCategory());
Person.add(P4.getCategory());
}
System.out.println(Person);
}
我怎样才能让程序一次打印一行Arraylist
而不是我现在的一大行。
最佳答案
使用 for-each 循环
for(String str : Person){
System.out.println(str);
}
关于java - 打印出一个数组列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26658938/