Loop to find max value
<p>hi i'm having a problem to write a loop which finds the largest value.</p>

<p>A list of integers and an integer variable are declared like this:
  List list;
  int max; </p>

<p>Assuming that some values (including negatives!) have been added to the list. i need to find the largest value in list and stores it in max.</p>

<pre><code>//  start of test code 
import java.util.*; 
public class ListTest 
{ 
private List&lt;Integer&gt; list; 
private int max;
public void findMaxInListTest()         { 
list = new ArrayList&lt;Integer&gt;(); // could be a Linked list 
list.add(0);
list.add(-99); 
list.add(99);
list.add(1320); 
list.add(470000); 
list.add(12);
list.add(-5000);
list.add(300);
/*#     max = starting value 
iterate through list to set max = max value in list 
in this case 470000     */ 
} 
}
</code></pre>

<p>i tried using this loop but then encounter an error:
    int max = list[0];
      for(int i=470000;i &lt; list.length;i++){
        if(list[i] > max){
          max = list[i];
        }
      }
    return max;</p>

<p>do you know which kind of loop that appropriate for this? Thanks</p>
