集合框架


public class Courier  extends  Person{
    private  String courierId;
    public Courier(){
        super();
    }
    public Courier(String courierId,String pwd){
//        super(pwd);
        this.courierId = courierId;
    }
    public Courier(String courierId,String name, String sex,Integer age,String pwd){
        super(name, pwd, sex, age);
        this.courierId = courierId;

    }
    public String getCourierId(){
        return courierId;

    }
    public void setCourierId(String courierId){
        this.courierId = courierId;
    }
    @Override
    public String toString(){
        return "快递员信息[编号="+courierId+",姓名=" +super.getName()+",性别="+super.getSex()+",年龄="+super.getAge()+"]";
    }

}



public class Demo01 {
    public static void main(String[] args) {

        Courier guo = new Courier("a1", "小郭", "男", 22, "上海");
        Courier huang = new Courier("a2", "小黄", "男", 22, "上海");
        Courier ana = new Courier("a3", "Ana", "女", 22, "上海");
        Courier mu = new Courier("a4", "穆大姐", "女", 33, "上海");

        List couriers = new ArrayList();
        couriers.add(guo);
        couriers.add(huang);
        couriers.add(ana);

        // 添加到指定位置
        couriers.add(1,mu);
        System.out.println("总共有"+couriers.size()+"个快递员");
        for (int i = 0; i < couriers.size(); i++) {
            Courier c =(Courier) couriers.get(i);
            System.out.println(c.getCourierId()+"\t"+c.getName());
        }

    }

}


public class Person {
    public String Name;
    public String pwd;
    public String sex;
    public Integer age;

    public Person() {
    }

    public Person(String name, String pwd, String sex, Integer age) {
        Name = name;
        this.pwd = pwd;
        this.sex = sex;
        this.age = age;
    }


    public String getName() {
        return Name;
    }

    public void setName(String name) {
        Name = name;
    }

    public String getPwd() {
        return pwd;
    }

    public void setPwd(String pwd) {
        this.pwd = pwd;
    }

    public String getSex() {
        return sex;
    }

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

    public Integer getAge() {
        return age;
    }

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




    @Override
    public String toString() {
        return "Person{" +
                "Name='" + Name + '\'' +
                ", pwd='" + pwd + '\'' +
                ", sex='" + sex + '\'' +
                ", age=" + age +
                '}';
    }

你可能感兴趣的:(集合框架)