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 does function identity () do?

521


Why a dead thread occurs?

578


What are different exception types exceptions available in java ?

484


Why do you canvas?

613


What does java edition mean?

540






How many types of voids are there?

540


What is the difference between multitasking and multithreading in Java

727


What are the different conditional statements?

561


What are the parts of methodology?

549


Similarity and difference between static block and static method ?

539


How to sort array of 0 and 1 in java?

543


Explain the use of shift operator in java. Can you give some examples?

545


What’s meant by anonymous class?

604


What are constants?

603


What happens if we override private method?

528