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 the restrictions imposed by a Security Manager on Applets?.
What is the difference between applet and application?
Why does java have two ways to create child threads?
Does java vector allow null?
What is array and arraylist in java?
Can you add null to a list java?
What is tcp and udp?
List some features of the abstract class.
How can you share data between two thread in Java?
Is 64bit faster than 32 bit?
Is it possible to use string in the switch case?
How to convert string to byte array and vice versa?
Why main() method is public, static and void in java ?
What is a class variable?
What is the format specifier?