What is difference between Iterator and for loop
Answer Posted / deepesh
An "Iterator object" is used to move through a Collection,
by calling Collection's iterator() method. By using for
loop, you are limited to that particular collection you are
traversing, while iterator gives freedom to work with any
collection.
iterator's job is to move through the sequence (without the
client programmer knowing or caring about the underlying
structure & its modification) using hasNext() and next().
remove() is provided "to remove the last element returned by
the iterator" and is called only per call after next().
Iterator can be used for Lists and Sets for forward
(unidirectional) traversal of elements without knowing their
size, which is nearly same concept for for-each loop.
Is This Answer Correct ? | 6 Yes | 1 No |
Post New Answer View All Answers
What about method local inner classes or local inner classes in java?
Is there any sort function in java?
What is the meaning of variable in research?
How do you create a null object?
What happens if a constructor is declared private?
How many bytes are there?
What is final, finally, finalize?
What is exception propagation?
What is blank final variable?
Is there any way to find whether software installed in the
system is registered by just providing the .exe file?
I have tried the following code but its just displaying the
directory structure in the registry.
Here the code :
package com.msi.intaller;
import java.util.Iterator;
import ca.beq.util.win32.registry.RegistryKey;
import ca.beq.util.win32.registry.RootKey;
public class RegistryFinder {
public static void main(String... args) throws Exception
{
RegistryKey.initialize(RegistryFinder.class.getResource("jRe
gistryKey.dll").getFile());
RegistryKey key = new RegistryKey(RootKey.HKLM,
"Software\\ODBC");
for (Iterator
Explain scope or life time of local variables in java?
How we can execute any code even before main method?
What is the difference between form & report?
What is diamond operator in java?
What is the difference between super class & sub class?