View Single Post
  #2 (permalink)  
Old 12-12-2007, 02:33 PM
revathi17 revathi17 is offline
Member
 
Join Date: Aug 2007
Posts: 22
revathi17 is on a distinguished road
Code:
import java.util.ArrayList; import java.util.Iterator; public class LargestNumber { public static void main(String[] args){ ArrayList<Integer> aList = new ArrayList<Integer>(); aList.add(101); aList.add(872); aList.add(777); aList.add(102); aList.add(23); Iterator<Integer> it = aList.iterator(); int max = 0; while(it.hasNext()){ int temp = it.next(); if(temp > max) max = temp; } System.out.println("Max value:"+max); } }
I think what happens is, only if you call it.next() it goes to the next element and continues iteration. This was something new for me too, i just tried giving a temp variable and it worked!!

-R
Reply With Quote