Answers for "java insert into arraylist user define"

7

java insert into arraylist

ArrayList<Integer> str=new ArrayList<Integer>();
str.add(0);
str.add(1);
 // Result = [0, 1]
    
str.add(1, 11);
 // Result = [0, 11, 1]
Posted by: Guest on March-06-2020
-1

how to get a user to add to an arraylist in java

public class chores {

	public static void main(String[] args) {
		
		Boolean close = false;
		
		ArrayList<String> name = new ArrayList();
		ArrayList<String> chores = new ArrayList();
		
		Scanner scanner = new Scanner(System.in);
		
		System.out.println("Please enter '0'to exit");
		System.out.println("Please enter name: ");
		String answer = scanner.nextLine();
		if (answer == "0") {
			close = true;
			System.out.println("Program has been terminated.");
		}
		else {
			name.add(answer);
			
			do {
				
				System.out.println("Please enter chore: ");
				answer = scanner.nextLine();
				chores.add(answer);
				System.out.println("Please enter name: ");
				name.add(answer);
				
				
			}while(answer != "0");
        }
    }
}
Posted by: Guest on May-18-2020

Code answers related to "java insert into arraylist user define"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language