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
What is a short in java?
What is e in java?
What is use of arraylist in java?
Why is it important to initialize a variable?
What is the purpose of an interface?
Which api is provided by java for operations on set of objects?
How many types of array are there?
When can we say that threads are not lightweight process in java?
What does super keyword do?
How listener identify that the event came from a particular object?
What are measurable parameters?
What is meant by oops concept in java?
How many arguments can a method have java?
How do constructors use this() and super()?
What is math exp in java?