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
How can you traverse a linked list in java?
What is data movement?
How to remove the trailing spaces from a string?
What is the static import?
Justify your answer that you can't define a method inside another method in java, if you can then how?
Which api is provided by java for operations on set of objects?
Which is fastest collection in java?
What is the arraylist in java?
Explain public static void main(string args[]) in java.
What is the difference between final, finally and finalize()?
How does compareto method work?
What is complexity in java?
What is floor in java?
Difference between this() and super() in java ?
What's the difference between int and integer in java?