Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class ArrListClass {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- ArrayList<String> namesList = new ArrayList<String>();
- String choise = "";
- while(!choise.contains("end")){
- System.out.println("Please choose :: <add> <remove> <print> <end> :: ");
- choise = scanner.nextLine();
- if(choise.equals("add")){
- String name = scanner.nextLine();
- namesList.add(name);
- }else if(choise.equals("remove")){
- System.out.println("Which number of list you want to remove?");
- byte indexToRemove = scanner.nextByte();
- if(indexToRemove > 0 && indexToRemove <= namesList.size()){
- namesList.remove(indexToRemove);
- }else{
- System.out.println("No such number !!");
- }
- }else if(choise.equals("print")){
- System.out.println(namesList);
- }
- }
- System.out.println("Goodbye!");
- }
- }
Add Comment
Please, Sign In to add comment