import java.util.Scanner;
import java.util.ArrayList;
public class Arr
{
public static void main(String Args[])
{
int index,choice,again;
String value;
Scanner s1 = new Scanner(System.in);
ArrayList<String> a1 = new ArrayList<String>();
a1.add("Delhi");
a1.add("Mumbai");
a1.add("Bangalore");
a1.add("Chennai");
a1.add("Nagpur");
System.out.println("Enter the choice");
System.out.println("1. Display the element");
System.out.println("2. Set the element");
System.out.println("3. delete the element");
do
{
System.out.println("Enter 1,2 or 3");
choice = s1.nextInt();
switch(choice)
{
case 1: System.out.println("Enter the position");
index= s1.nextInt();
System.out.println("the element is" + a1.get(index));
break;
case 2: System.out.println("Enter the position");
index= s1.nextInt();
System.out.println("Enter the element");
value= s1.nextLine();
a1.set(index,value);
System.out.println("Your new ArrayList is" + a1);
break;
case 3: System.out.println("Enter the position");
index= s1.nextInt();
a1.remove(index);
System.out.println("the new arraylist is" + a1);
break;
default: System.out.println("Invalid choice");
}
System.out.println("Do you want to continue.. Enter '1' otherwise 0");
again= s1.nextInt();
}while(again==1);
}
}
Comments
Post a Comment