Answers for "how to add to arraylist java"

1

adding items to an arraylist

import java.util.ArrayList;

public class Main {
  public static void main(String[] args) {
    ArrayList<String> cars = new ArrayList<String>();
    cars.add("Volvo");
    cars.add("BMW");
    cars.add("Ford");
    cars.add("Mazda");
    System.out.println(cars);
  }
}
Posted by: Guest on September-02-2021
2

arraylist add

ArrayList<String> languages = new ArrayList<String>(); 
languages.add("PHP");
languages.add("JAVA");
languages.add("C#");
ArrayList<int> numbers = new ArrayList<int>(); 
numbers.add(9);
numbers.add(14);
numbers.add(2);
Posted by: Guest on June-17-2021
2

how to add to an arraylist java

import java.util.ArrayList;
public class Details {
    public static void main(String[] args) {

        //ArrayList<String> Declaration
        ArrayList<String> al= new ArrayList<String>();
        //add method for String ArrayList
        al.add("Ram");
        al.add("Shyam");
        al.add("CPS");
        al.add("John");
        al.add("Steve");
        System.out.println("Elements of ArrayList of String Type: "+al);
Posted by: Guest on July-14-2020
0

arraylist add method

public void add(int index, E element)	// no return value
Posted by: Guest on May-16-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 "how to add to arraylist java"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language