zoukankan      html  css  js  c++  java
  • 题目:自定义4个学生对象,添加到集合,并遍历

    /*
    *题目:自定义4个学生对象,添加到集合,并遍历
    *
    * 思路
    * 1.创建一个Student学生类,四个部分
    * 2.创建一个集合,用来存储学生对象,泛型<Student>
    *3.根据类,创建四个学生对象
    * 4.将4个学生添加到集合中:add
    * 5.遍历集合:for、size、get
    *
    * */
    
    
    import java.util.ArrayList;
    
    public class Demo02ArrayListStudent {
        public static void main(String[] args) {
            ArrayList<Student>list=new ArrayList<>();
    
            Student one = new Student("洪七公",20);
            Student two = new Student("欧阳锋",22);
            Student there = new Student("黄药师",21);
            Student four = new Student("段智兴",26);
    
            list.add(one);
            list.add(two);
            list.add(there);
            list.add(four);
    
            //
            for (int i = 0; i < list.size(); i++) {
                Student stu=list.get(i);
    
                System.out.println("姓名:"+stu.getName()+",年龄:"+stu.getAge());
            }
    
    
    
        }
    
    }

    package demo05;
    
    public class Student {
        private String name;
        private int age;
    
        public Student() {
    
        }
    
        public Student(String name, int age) {
            this.name = name;
            this.age = age;
        }
    
        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;
        }
    }
    

      

      

  • 相关阅读:
    输入分隔符
    GO
    match|align|identify|cover_rate
    KEGG
    InterProScan
    Functional annotation
    GeneWise
    get middle lines
    goland debug web app with urfave cli
    go mod proxy
  • 原文地址:https://www.cnblogs.com/pengxiaoxiang123/p/13568042.html
Copyright © 2011-2022 走看看