-----------------------------------------------------------------------------How do i do delete element array in java. I have done add element in array but im not sure how to remove element from the array.---------------------------------------------------------------------------------------------------------
this is the code:
import java.util.Scanner;
import java.util.*;
public class OnlineBookStore extends Welcome {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
OnlineBookStore e1 = new OnlineBookStore();
e1.sayWelcome();
int option = in.nextInt();
in.nextLine();
if (option == 1) {
String pass;
System.out.println("Enter the password: ");
pass = in.nextLine();
if(pass.equals("best")) {
System.out.println("Welcome Admin. Which option would you like to choose?");
System.out.println("1. Add");
System.out.println("2. Delete");
System.out.println("3. Modify");
int choice = in.nextInt();
in.nextLine();
if (choice == 1) {
List<String> list = new ArrayList<String>();
do {
System.out.println("Current list is" + list);
System.out.println("add (y/n)");
if (in.next().startsWith("y")) {
System.out.println("Enter: ");
list.add(in.next());
} else {
break;
}
} while(true);
in.close();
String[] arr = list.toArray(new String[0]);
System.out.println("Array is " + Arrays.toString(arr));
}
}else {
System.out.println("Wrong password.");
}
}
if (option == 2) {
String pass;
System.out.println("Enter the password: ");
pass = in.nextLine();
if(pass.equals("bbb")) {
System.out.println("History of sold and stock books");
System.out.println("Sold books:");
System.out.println("Life Without Limits");
System.out.println("Think and Grow Rich");
System.out.println("");
System.out.println("Stock Books:");
System.out.println("Lie of Pi");
System.out.println("The Hobbit");
}else {
System.out.println("Wrong password.");
}
}
if (option == 3) {
String user;
System.out.println("Enter your username: (so we know if you are a registered user.)");
user = in.nextLine();
if(user.equals("Ossar") || user.equals("Goala") || user.equals("Howale")) {
System.out.println("");
System.out.println("");
}else {
System.out.println("You are not a registered user");
}
}
}
}