I have a java class called StudentList and I want to make a method which would go through each student and check their group numbers. Then add them to an arraylist, if the group number is already inside the arraylist then it would skip it. But how do I make a loop that would skip duplicates?
I've tried using the for loop but I can't think of a solution past this one point:
public ArrayList<Integer> getAllGroupNumbers() {
ArrayList<Integer> a = new ArrayList<Integer>();
for(int i = 0; i < list.size(); i++)
{
if(list.get(i).getGroupNumber() != ...)
}
}