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
Is call by reference possible in java?
Is java an ide?
How do you compare objects in java?
Explain the difference between extends thread vs implements runnable in java?
do I need to use synchronized on setvalue(int)? : Java thread
What is the difference between the file and randomaccessfile classes?
What is java lang string?
What are streams?
What are the advantages and disadvantages of object cloning?
Differences between traditional programming language and object oriented programming language?
Write a method to check if input string is palindrome?
What do you understand by java virtual machine?
Can we have multiple public classes in a java source file?
which one is more efficient int x; 1. if(x==null) 2.if(null==x) state which one either 1 or 2?
How does arraylist work in java?