Cur Surs
Cur Surs
If we want to get Objects One by One from the Collection then we should go for
Cursors.
1) Enumeration:
==============
We can Use Enumeration to get Objects One by One from the Collection.
We can Create Enumeration Object by using elements().
Methods:
1) public boolean hasMoreElements();
2) public Object nextElement();
Example :
package list;
import java.util.Enumeration;
import java.util.Vector;
System.out.println(v);
Enumeration enumeration = v.elements();
while (enumeration.hasMoreElements()) {
Object element = enumeration.nextElement();
System.out.println(element);
}
}
Limitations of Enumeration:
Enumeration Concept is Applicable Only for Legacy Classes and it is Not a
Universal
Cursor.
By using Enumeration we can Perform Read Operation and we can't Perform Remove
Operation.
To Overcome Above Limitations we should go for Iterator.
forEach loop:
package list;
import java.util.Enumeration;
import java.util.Vector;
System.out.println(v);
for (Object v1 : v) {
System.out.println(v1);
}