Answers for "iterator and enumeration in java"

1

iterator vs enumerator

Iterators allow the caller to remove elements from the underlying collection 
during the iteration with its remove() method. You cannot add/remove elements 
from a collection when using enumerator.
Enumeration is available in legacy classes i.e Vector/Stack etc. 
Iterator is available in all modern collection classes.
Another minor difference is that Iterator has improved method names e.g.
Enumeration.hasMoreElement() has become Iterator.hasNext(),
Enumeration.nextElement() has become Iterator.next() etc.
Posted by: Guest on December-05-2020
0

iterate over enum java

for (DaysOfWeekEnum day : DaysOfWeekEnum.values()) { 
    System.out.println(day); 
}
Posted by: Guest on July-15-2021
0

difference between iterator vs enumerator

Iterators allow the caller to remove elements from the underlying collection 
during the iteration with its remove() method. You cannot add/remove elements 
from a collection when using enumerator.
Enumeration is available in legacy classes i.e Vector/Stack etc. 
Iterator is available in all modern collection classes.
Another minor difference is that Iterator has improved method names e.g.
Enumeration.hasMoreElement() has become Iterator.hasNext(),
Enumeration.nextElement() has become Iterator.next() etc
Posted by: Guest on December-05-2020

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language