标签:
package ArrayListT; import java.util.ArrayList; import java.util.Iterator; /*import java.util.Scanner;*/ import java.util.Map.Entry; public class ArrayListedTest{ public static void main(String[] args) { /*String name = null; int id; int age; int i = 0;*/ /* Scanner input = new Scanner(System.in); do { System.out.println("请输入学生学号:"); id = input.nextLong(); System.out.println("请输入学生姓名:"); name = input.nextLine(); System.out.println("请输入学生年龄:"); age = input.nextInt(); Student stu = new Student(id,name,age); i++; } while (id!= 0);*/ int i = 0; ArrayList<Student> arraylist = new ArrayList<Student>(); Student stu0 = new Student(1,"成龙",25); Student stu1 = new Student(2,"张三",23); Student stu2 = new Student(3,"王五",24); arraylist.add(stu0); arraylist.add(stu1); arraylist.add(stu2); Iterator st = arraylist.iterator(); while(st.hasNext()){ Student stu = arraylist.next(); if(stu.getId() == 0){ System.out.println("结束录入!"); i = 0; } } } }
package ArrayListT; public class Student { private String name = null; private long id; private int age; int i ; private String[] stu; public Student() { super(); } public Student(long id, String name, int age) { super(); this.setName(name); this.setId(id); this.setAge(age); } public String getName() { return name; } public void setName(String name) { this.name = name; } public long getId() { return id; } public void setId(long id) { this.id = id; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } public String[] getStu() { return stu; } public void setStu(String[] stu) { this.stu = stu; } }
标签:
原文地址:http://www.cnblogs.com/xiaolei121/p/5759100.html