我创建了一个名为 Student 的类,其中包含有关学生的信息。
public class Student {
private int totalPoint;
private int antalKurser;
private String program;
// here is constructor and get/set methods
}
我还尝试从该类创建一个 ArrayList,根据我的理解,我应该写:
public class createArrayList {
ArrayList<Student> studentList new ArrayList<>();
}
但是 Netbeans 给了我一个错误,如果我将鼠标悬停在该行上,它会显示“;” expexted,但我确信我已经写了(上面的代码片段是复制粘贴的)。当我运行代码时,它显示“编译时有错误”,但仍然运行。
在其他地方找到我也可以写:
ArrayList<Class> studentList = new ArrayList<>();
但是应用程序如何知道应该从哪个类创建列表呢?
Student 类位于另一个 java 文件中,但位于同一个包中。我错过了什么?
最佳答案
尝试
public class createArrayList {
ArrayList<Student> studentList = new ArrayList<Student>();
}
关于java - 从类创建数组列表 - java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47316412/