TsetsoP

ArrListClass

Mar 6th, 2021 (edited)
437
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.12 KB | None | 0 0
  1. import java.util.*;
  2. public class ArrListClass {
  3.  
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.  
  7.         ArrayList<String> namesList = new ArrayList<String>();
  8.         String choise = "";
  9.  
  10.         while(!choise.contains("end")){
  11.             System.out.println("Please choose :: <add> <remove> <print> <end> :: ");
  12.             choise = scanner.nextLine();
  13.  
  14.             if(choise.equals("add")){
  15.                 String name = scanner.nextLine();
  16.                 namesList.add(name);
  17.  
  18.             }else if(choise.equals("remove")){
  19.                 System.out.println("Which number of list you want to remove?");
  20.                 byte indexToRemove = scanner.nextByte();
  21.  
  22.                 if(indexToRemove > 0 && indexToRemove <= namesList.size()){
  23.                     namesList.remove(indexToRemove);
  24.                 }else{
  25.                     System.out.println("No such number !!");
  26.                 }
  27.  
  28.             }else if(choise.equals("print")){
  29.                 System.out.println(namesList);
  30.             }
  31.         }
  32.         System.out.println("Goodbye!");
  33.  
  34.     }
  35.  
  36. }
Add Comment
Please, Sign In to add comment