user5862095
user5862095

Reputation:

Creating a arraylist from a class - java

I've created a class called Student which will contain information about students.

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:

public class createArrayList {
        ArrayList<Student> studentList new ArrayList<>();
}

However Netbeans gives me an error and if I hover the line it says ';' 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. What am I missing?

Upvotes: 0

Views: 53

Answers (1)

Josh Withee
Josh Withee

Reputation: 11336

Try

public class createArrayList {
        ArrayList<Student> studentList = new ArrayList<Student>();
}

Upvotes: 1

Related Questions