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
Can we declare main () method as non static?
What is the do while loop syntax?
what is comparable and comparator interface?
What is an empirical question?
Can we sort hashset in java?
How to make a class or a bean serializable?
What is the purpose of javac exe?
What data type is string java?
Does it matter in what order catch statements for filenotfoundexception and ioexception are written?
Explain the difference between abstract class and interface in java?
What is a pattern what is an anti pattern?
How the interruptible method gets implemented?
From the two, which would be easier to write: synchronization code for ten threads or two threads?
Give the difference between the println method and sqrt method?
write a program that list all permutations of ABCDEF in which A appears before B?