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


Please Help Members By Posting Answers For Below Questions

What is a short in java?

693


What is e in java?

726


What is use of arraylist in java?

810


Why is it important to initialize a variable?

724


What is the purpose of an interface?

765


Which api is provided by java for operations on set of objects?

1182


How many types of array are there?

729


When can we say that threads are not lightweight process in java?

818


What does super keyword do?

774


How listener identify that the event came from a particular object?

1702


What are measurable parameters?

773


What is meant by oops concept in java?

725


How many arguments can a method have java?

790


How do constructors use this() and super()?

787


What is math exp in java?

754