我这里有一个Arraylist:
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);
}
Run Code Online (Sandbox Code Playgroud)
如何让程序一次打印出Arraylist一行而不是我现在的一行.
用于每个循环
for(String str : Person){
System.out.println(str);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
89 次 |
| 最近记录: |