how to put numbers in an arraylist code example
Example 1: java declare arraylist with int values
ArrayList<Integer> numbers = new ArrayList<>(Arrays. asList(1, 2, 3, 4, 5, 6));
Example 2: 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");
}
}
}