Reputation: 587
When I obtain iterator over an ArrayList and use the method next() on it, does it return only next element or it return and remove elements from the iterator. like
Iterator i = list.iterator();
while(i.hasNext())
System.out.print(i.next()+" ");
Upvotes: 0
Views: 839
Reputation: 39477
Calling next() just moves a pointer to the next element
and returns the element. It does not remove any elements.
For more details see here.
http://en.wikipedia.org/wiki/Iterator#Java
http://docs.oracle.com/javase/7/docs/api/java/util/Iterator.html
Iterators also have a remove() method. That method removes elements.
Upvotes: 5