public class Test01 {
public static void main(String[] args) {
int[] arr01 = new int[10];
String[] arr02 = new String[5];
//动态赋值
arr01[0] = 13;
arr01[1] = 15;
for(int i=0; i<10; i++) { //i<arr01.length
arr01[i] = 10*i;
}
for(int i=0; i<10; i++) { //arr01.length 数组的遍历
System.out.print(arr01[i]+"\t");
}
System.out.println("###########");
//增强for循环
for(int m:arr01) { //只用来读取数组里面的内容
System.out.print(m);
}
User[] arr03 = new User[3];
arr03[0] = new User(1001, "xie0");
arr03[1] = new User(1002, "xie1");
for(int i=0; i<arr03.length; i++) {
System.out.println(arr03[i].getName());
}
}
}
class User{
private int id;
private String name;
public User(int id, String name) {
super();
this.id = id;
this.name = name;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
Java——数组、、对象数组、增强for循环
最新推荐文章于 2022-06-21 18:36:29 发布