首页 > 其他 > 详细

Arraylist Student

时间:2020-05-31 10:30:51      阅读:33      评论:0      收藏:0      [点我收藏+]

1.student java

package ArrayList;

public class Student {
    private String name;
    private int age;
    private String sex;

    public Student() {
    }

    public Student(String name, int age, String sex) {
        this.name = name;
        this.age = age;
        this.sex = sex;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }
}

2.Student_demo

package ArrayList;
import java.util.ArrayList;
public class student_demo {
    public static void main(String[] args) {
        Student one = new Student("Alex", 18, "male");
        Student two = new Student("Hull", 20, "male");
        Student three = new Student("Linda", 21, "female");
        Student four = new Student("Miranda", 18, "female");
        ArrayList<Student> list = new ArrayList<>(10);
        list.add(one);
        list.add(two);
        list.add(three);
        list.add(four);
        for(int i=0;i<list.size();i++){
            Student stu=list.get(i);
            System.out.println("student: "+stu.getName()+" age: "+stu.getAge()+" sex: "+stu.getSex());
        }


    }
}

ret://

student: Alex age: 18 sex: male
student: Hull age: 20 sex: male
student: Linda age: 21 sex: female
student: Miranda age: 18 sex: female

Arraylist Student

原文:https://www.cnblogs.com/resort-033/p/12996372.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!