As we have discussed cursors defination , below are the differentiation among the cursors by using their properties.
Internal implementation of cursors Example :
package indrajeet.singh.cursors.imp;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.ListIterator;
import java.util.Vector;
public class CursorsDemo {
public static void main(String[] args) {
Vector v=new Vector();
Enumeration e=v.elements();
Iterator itr=v.iterator();
ListIterator litr=v.listIterator();
System.out.println(e.getClass().getName());
System.out.println(itr.getClass().getName());
System.out.println(litr.getClass().getName());
}
}
Output:
java.util.Vector$1
java.util.Vector$Itr
java.util.Vector$ListItr
Properties | Enumeration | Iterator | ListIterator |
1. where we can apply | legacy classes only | any collection object | only for List object |
2. Its legacy ? | Yes(1.0 version) | No(1.2 version) | No(1.2 version) |
3. Movement directioin | single direction forward | single direction forward | both direction |
4. Allowed opeation | only read | only read , remove | read/remove/replace/add |
5. how we can get ? | by using elements() of Vector class | by using iterator() of Collection interface | by using listIterator() of List Interface |
6. methods | hashMoreElements() | hashNext() | having 9 methods for both direction |
nextElement() | next() | ||
remove() |
Internal implementation of cursors Example :
package indrajeet.singh.cursors.imp;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.ListIterator;
import java.util.Vector;
public class CursorsDemo {
public static void main(String[] args) {
Vector v=new Vector();
Enumeration e=v.elements();
Iterator itr=v.iterator();
ListIterator litr=v.listIterator();
System.out.println(e.getClass().getName());
System.out.println(itr.getClass().getName());
System.out.println(litr.getClass().getName());
}
}
Output:
java.util.Vector$1
java.util.Vector$Itr
java.util.Vector$ListItr