[英]Creating a arraylist from a class - java
I've created a class called Student which will contain information about students. 我创建了一个名为Student的类,其中将包含有关学生的信息。
public class Student {
private int totalPoint;
private int antalKurser;
private String program;
// here is constructor and get/set methods
}
I'm also trying to create a ArrayList from that class and from what I understand i should write: 我也试图根据该类以及据我所知应该写的内容创建一个ArrayList:
public class createArrayList {
ArrayList<Student> studentList new ArrayList<>();
}
However Netbeans gives me an error and if I hover the line it says ';' 但是Netbeans给我一个错误,如果我将鼠标悬停在行上,它会显示“;”。 expexted but I'm positive I have written that (above snippet is copy-pasted).
扩展,但是我很肯定我已经写过(上面的代码片段是复制粘贴的)。 When I run the code it says "compiled with errors" but still runs.
当我运行代码时,它说“编译错误”,但仍然运行。
Found somewhere else I also could write: 在其他地方我也可以写:
ArrayList<Class> studentList = new ArrayList<>();
But then how does the application know which class it should create a list from? 但是,应用程序如何知道应该从哪个类创建列表?
The class Student is in another javafile but is in the same package. 学生类在另一个javafile中,但在同一包中。 What am I missing?
我想念什么?
Try 尝试
public class createArrayList {
ArrayList<Student> studentList = new ArrayList<Student>();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.