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 do you implement singleton class?
What are three ways in which a thread can enter the waiting state in java programming?
How the metacharacters are different from the ordinary characters?
what do you mean by java annotations?
What is dot operator?
Is multiple inheritance supported by java?
What do you understand by java virtual machine?
Explain the difference between static and dynamic binding in java?
What is the difference between a checked and an unchecked exception?
Can a hashset contain duplicates java?
Convert a BST into a DLL and DLL to BST in place.
What is the range of the short type?
Why hashset is used in java?
What is a percentage sign called?
Which package has light weight components in java programming?