Re: Iterators in Java and C++
Hi
Razii wrote:
> If the problem is that "You should be able to access the object
> without advancing the iterator", where am I calling next in this
> syntax.
Easy...
> int[] nums = { 1, 2, 3, 4, 5, 6 };
>
> for(int n : nums) {
^^^^^^^^^^^^
Here...
> System.out.println(n);
> }
>
> Or
>
> List list = getList();
>
> for (Object element : list) {
^^^^^^^^^^^^^^^^^^^^^
.... and here.
> out.println(element);
>
> // Do something else with this element
> }
Markus
|