Java program that load data on structure type ArrayList, adds, removes, replaces elements from the list according to command. The output and the code image is attached.
import java.util.ArrayList;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
ArrayList<Integer> lsta = new ArrayList();
Scanner sc = new Scanner(System.in);
int i;
int vlu;
int vlu1;
int comd;
do {
do {
System.out.print("Comand: ");
comd = sc.nextInt();
} while (!(comd>=0 & comd<=3));
switch (comd) {
case 0 :
System.out.print("Value: ");
vlu = sc.nextInt();
lsta.add(vlu);
break;
case 1:
do {
System.out.print("Value 1: ");
vlu = sc.nextInt();
} while (vlu > lsta.size());
System.out.print("Value 2: ");
vlu1 = sc.nextInt();
lsta.set(vlu,vlu1);
break;
case 2:
do {
System.out.print("Value: ");
vlu = sc.nextInt();
} while (vlu > lsta.size());
lsta.remove(vlu);
break;
}
} while (!(comd==3));
System.out.println("The contents of the arraylist:" + lsta);
}
}
To learn more about Java method ArrayList see: https://brainly.com/question/23189171
#SPJ4