A Developer Gateway To IT World...

Techie Uncle Software Testing Core Java Java Spring C Programming Operating System HTML 5 Java 8 ES6 Project

Create an ArrayList and add username email and rollno in list.

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);


Complete Program Code:



import java.util.ArrayList;
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);
       
    }
}


LEARN TUTORIALS

.

.