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 arrays sort in java?
Can we change the scope of the overridden method in the subclass?
Is list thread safe in java?
What is the range of a character variable?
What is not thread safe?
How to perform quicksort in java?
What is an argument java?
Can an abstract class be a final class?
What about member inner classes?
Is char * a string?
What is the full meaning of java?
Program to Find the second largest element in an array.
How can we use primitive data types as objects?
Discuss 2D arrays.
How to solve the problem of generating the unique hash keys with hash function?