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 is the difference between preemptive scheduling and time slicing in java programming?
What is the purpose of static methods and static variables?
How can you make sure that your singleton class will always return single instance in multi-threaded environment?
Why is it called buffering?
Can constructor be inherited?
What is a flag variable?
How will you call an Applet using Java Script Function?
Write a program based on Java script program.
Can a class be private?
How to run a JAR file through command prompt?
Can Exception handling we can handle multiple catch blocks?
What do bitwise operators do?
Can size_t be negative?
Is void a return type?
Where we write javascript code in html page?