Loading... List<Type> variable = new ArrayList<>([size]); Type:int String method ... size:可写可不写 class user{ private String name; private int age; public user(String string, int i) { this.name = string; this.age = i; } public String getName() { return name; } public int getAge() { return age; } } List<user> list = new ArrayList<>(); list.add(new user("张三",15)); ---------- 集合的遍历: 方法一 for (int i = 0; i < list.size(); i++) { System.out.print(list.get(i).getName()); System.out.println(list.get(i).getAge()); } 方法二 for (user user : list) { System.out.println(user.getAge() + user.getName()); } Last modification:March 21, 2021 © Allow specification reprint Like 0 如果觉得我的文章对你有用,请随意赞赏
Comment here is closed