What is difference between Iterator and for loop
Answer Posted / a.jyotsna
The Iterator is not implemented as an
indexed loop, at least not in Sun Java. The collection
always has a
getter armed with the iterator's next value. Much of the
collection's
internal implementation is done via the iterator. But the
pieces of
ArrayList that are optimized for speed, skip bounds
checking and use int
array offsets to do their work.
I would like to know what is the difference between these 2.
>
> ArrayList list = new ArrayList
>
> for(int i=0; i<list.size(); i++){
> //do stuff
> }
>
> Iterator i = list.iterator();
>
> while(i.hasNext(){
> do stuff
> }
| Is This Answer Correct ? | 6 Yes | 6 No |
Post New Answer View All Answers
What are generic methods?
Explain the differences between abstraction and encapsulation?
Is java developer a good career?
Is 9 a prime number?
What is the equal sign?
What is a container in a gui?
What is static class
What is api data?
How is final different from finally and finalize?
What is nested class?
Can substring create new object?
What are java methods?
What is native method in java?
What type of variable is error flag?
Differentiate between overriding and overloading cases?