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


Please Help Members By Posting Answers For Below Questions

What are the restrictions imposed by a Security Manager on Applets?.

2061


What is the difference between applet and application?

544


Why does java have two ways to create child threads?

464


Does java vector allow null?

539


What is array and arraylist in java?

525






Can you add null to a list java?

583


What is tcp and udp?

595


List some features of the abstract class.

587


How can you share data between two thread in Java?

522


Is 64bit faster than 32 bit?

576


Is it possible to use string in the switch case?

555


How to convert string to byte array and vice versa?

582


Why main() method is public, static and void in java ?

591


What is a class variable?

568


What is the format specifier?

516