I am trying to remove all duplicate objects with the same value in one property.I have courses[]
objects and they all contain a courseLevel
that is composed of one four digit integer
.
I am incrementing x
from 0
in a loop and storing the data and reseting it every iteration of the loop to store new information in the next incremented courses[x]
object.
for (int n = 0; n < courses.length; n++) {
if (courses[x].getCourseLevel() == courses[n].getCourseLevel()) {
System.out.println("Duplicate" + courses[x]);
}
}
As you can see I start with courses[x]
and want to check if its courseLevel
is equal to any of the other objects that have been created to that point but the problem is it checks its self,How can I check all courses[n]
except courses[x]
Tried using equals() but couldn't compare int types.