ArrayList problem (finding largest no)
I am working on an assignment and I have to find largest number from an ArrayList using Iterator. I wrote following code.
It compiles fine but the output is not as required.
ArrayList <Integer>alist = new ArrayList<Integer>();
// finding the largest number in the ArrayList
Iterator<Integer> it = alist.iterator();
int max = 0;
if( it.next() > max)
max = it.next();
Output should be 872. I am not sure what is happening.
Please look into this.