
write a program to create an vector and listeterator.and value should be enter through keyboard.

Java enter list elements through keyboard
import java.util.*;
class ArrayListAndListIterator
{
public static void main(String[]args){
List l = new ArrayList();
Scanner input=new Scanner(System.in);
System.out.println("Enter 5 elements: ");
for(int i=0;i<5;i++){
String st=input.next();
l.add(st);
}
ListIterator listIterator = l.listIterator();
System.out.println("Elements are: ");
while (listIterator.hasNext()) {
System.out.println(listIterator.next());
}
}
}

Java enter vector element through keyboard
import java.util.*;
class VectorAndListIterator{
public static void main(String[]args){
Vector vector = new Vector();
Scanner input=new Scanner(System.in);
System.out.println("Enter 5 elements: ");
for(int i=0;i<5;i++){
String st=input.next();
vector.addElement(st);
}
ListIterator listIterator = vector.listIterator();
System.out.println("Elements are: ");
while (listIterator.hasNext()) {
System.out.println(listIterator.next());
}
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.