Returning the highest value java
<p>I'm trying to search an ArrayList and find the highest student mark. The values are randomly inputted. I have written code that works <em>if</em> the values are in order. But when I try to enter values in a random order, the loop always returns the last value entered! (Which is starting to frustrate me a little as I thought it worked!) It's probably something simple but I have missed the point again.</p>

<p>One other note <code>.getName</code> retrieves the student name with the highest mark.</p>

<p>Here is the code:</p>

<pre><code>public String top()
{
    int highest = 0;
    int k;

    for (k = 0; k &lt; people.size();k++)
    {
        if (people.get(k).getMark() &gt; highest)
        {
            highest = k;
        }       
    }
    return people.get(highest).getName();
}
</code></pre>
