zoukankan      html  css  js  c++  java
  • Arraylist Student

    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

  • 相关阅读:
    正则表达式
    Ajax跨域问题---jsonp
    Ajax
    字符串总结
    js 字符串加密
    jsDate()
    HDU 5430 Reflect
    HDU 5429 Geometric Progression
    HDU 5428 The Factor
    POJ 2485 Highways
  • 原文地址:https://www.cnblogs.com/resort-033/p/12996372.html
Copyright © 2011-2022 走看看