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 do you mean by exception handling in Java?
Explain about fail safe iterators in java?
What is the program development process?
What do you know about the garbate collector?
When is the finalize() called? What is the purpose of finalization?
what is meant wrapper classes?
What is the purpose of using java.lang.class class?
Explain about sets?
What is nested top-level class?
How many arguments can be passed to main ()?
What are the Main functions of Java?
What is e java?
What is boolean in java?
How do you check if a number is a perfect square?
Give example to differentiate between call by value and call by reference.