Programming steps:
1. Create an ArrayList
ArrayList mylist = new ArrayList();
2. add rollno in list:
System.out.println("Enter rollno: ");
Scanner sc = new Scanner(System.in);
int i, n;
n=sc.nextInt();
mylist.add(n);
3. add username in list:
Scanner sc1 = new Scanner(System.in);
System.out.println("Enter username: ");
String name=sc1.nextLine();
mylist.add(name);
4. add email in list:
System.out.println("Enter email: ");
String em=sc1.nextLine();
mylist.add(em);
5. Use cursor Iterator to display list items:
Iterator myit = mylist.iterator();
while(myit.hasNext())
{
System.out.println(myit.next());
}
Complete Program Code:
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Scanner;
public class A
{
public static void main(String a[])
{
ArrayList mylist = new ArrayList();
System.out.println("Enter rollno: ");
Scanner sc = new Scanner(System.in);
int i, n;
n=sc.nextInt();
mylist.add(n);
Scanner sc1 = new Scanner(System.in);
System.out.println("Enter username: ");
String name=sc1.nextLine();
mylist.add(name);
System.out.println("Enter email: ");
String em=sc1.nextLine();
mylist.add(em);
System.out.println("List is: "+mylist);
Iterator myit = mylist.iterator();
while(myit.hasNext())
{
System.out.println(myit.next());
}
}
}