What is difference between Iterator and for loop
Answer Posted / amit r
There are basic 3 differences between For and Iterater.
1.
Using Iterater we can check if the object exists or not by using hasNext method. Where as in For Loop, there is not such method. Therefore, For Loop will be executed at fixed amount at every time.
2.
Using Iterator we can add or remove objects from the underlying collection. In For Loop, if we do so, concurrent modification exception will be thrown.
3.
Using Iterator we can move forward or backward where as For Loop can't.
:)
| Is This Answer Correct ? | 7 Yes | 6 No |
Post New Answer View All Answers
How to split arraylist elements in java?
Is main a function?
Difference between object instantiation and construction ?
How do you create a bulleted list?
Why are the methods of the math class static?
Is Java a dying language?
What is procedure writing?
What is native method in java?
When is the arraystoreexception thrown?
Why do we need wrapper classes?
What classes of exceptions may be thrown by a throw statement?
What is a dynamic array in java?
What is a vararg?
Does .length start 0 java?
Can we make the abstract methods static in java?