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

How do you implement singleton class?

513


What are three ways in which a thread can enter the waiting state in java programming?

682


How the metacharacters are different from the ordinary characters?

564


what do you mean by java annotations?

544


What is dot operator?

573






Is multiple inheritance supported by java?

506


What do you understand by java virtual machine?

705


Explain the difference between static and dynamic binding in java?

540


What is the difference between a checked and an unchecked exception?

545


Can a hashset contain duplicates java?

492


Convert a BST into a DLL and DLL to BST in place.

669


What is the range of the short type?

580


Why hashset is used in java?

532


What is a percentage sign called?

615


Which package has light weight components in java programming?

673