.equals() method to detect duplicate array elements (tried @Override)
<p>I have a simple loop that checks for any duplicate results,
where studresults holds my results , result is the object result given to the method and r is the current object from the array.
I have been using this method successfully throughout the program although it is not working in this case even though when I debug result and r , are exactly the same does anyone know why this might be? I have tried @Override already as suggested in other answers to no avail.</p>

<p>I am trying to stop duplicated array elements by throwing an exception.</p>

<pre><code>for(Result r : studresults)
   {
     if(r.equals(result)) 
       {
           return false;
       }
   }
</code></pre>

<p>EDIT OK HERE IS THE WHOLE CLASS></p>

<pre><code>package ams.model;

import java.util.ArrayList;
import java.util.Arrays;

import ams.model.exception.EnrollmentException;

public abstract class AbstractStudent implements Student {
private int studentId;
private String studentName;
private ArrayList&lt;Course&gt; studcourses = new ArrayList&lt;Course&gt;();
private ArrayList&lt;Result&gt; studresults = new ArrayList&lt;Result&gt;();


public AbstractStudent(int studentId, String studentName) {
    this.studentId = studentId;
    this.studentName = studentName;

}


public String getFullName() {


    return studentName;
}


public int getStudentId() {


    return studentId;
}


public Result[] getResults() {  

    Result[] res = studresults.toArray(new Result[0]);
    if(res.length &gt; 0 )
    {
    return res;
    }
    return null;

}


public boolean addResult(Result result)
{
    for(Result r : studresults)
    {
        if(r.equals(result))
        {
                return false;
        }
    }

    studresults.add(result);
    return true;
}

public void enrollIntoCourse(Course c)
{
    //for re-enrollment
    if(studcourses.contains(c))
    {
        studcourses.remove(c);
        studresults.clear();
    }
    studcourses.add(c);
}

public void withdrawFromCourse(Course c) throws EnrollmentException
{
    if(studcourses.size() &gt; 0)
    {
        studcourses.remove(c);
    }
    else
        throw new EnrollmentException();
}
public Course[] getCurrentEnrolment() 
{
    return studcourses.toArray(new Course[0]);
}


public abstract int calculateCurrentLoad();


public int calculateCareerPoints() {
    // TODO Auto-generated method stub
    return 0;
}

public String toString()
{
    return studentId + ":" + studentName +":" + calculateCurrentLoad();
}
</code></pre>

<p>}</p>
