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 does function identity () do?
Why a dead thread occurs?
What are different exception types exceptions available in java ?
Why do you canvas?
What does java edition mean?
How many types of voids are there?
What is the difference between multitasking and multithreading in Java
What are the different conditional statements?
What are the parts of methodology?
Similarity and difference between static block and static method ?
How to sort array of 0 and 1 in java?
Explain the use of shift operator in java. Can you give some examples?
What’s meant by anonymous class?
What are constants?
What happens if we override private method?