我正在尝试制作一个学生应用程序。用户给出学生人数,然后他将添加学生姓名列表,该列表将存储在 ArrayList<String>
中。 .
ArrayList<String> Names= new ArrayList<String>();
获取姓名后,我想将它们添加到学生类(class)中。
public Class Student{
private String Name;
private ArrayList<Double> Grade=new ArrayList<Double>();
public Student(String name){Name=name;}
....
}
为此,我创建了一个学生类型 ArrayList
:
ArrayList<Student> Students= new ArrayList<Student>();
我想做的是以下但无法弄清楚
Student (Retreive the first Name from ArrayList Names) = new Student(Also do the Same);
我想为每个 Student
执行此操作输入后,我还想知道如何添加每个 Student
的成绩列表.
最佳答案
for (String name: Names)
Students.add(new Student(name));
关于java - 从名称的 ArrayList 初始化类的 ArrayList,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22435945/