Answers for "add values to arraylist java"

1

add value with n variable with Arraylist in java

Scanner in = new Scanner(System.in);
int n = 5;
ArrayList<String> addName = new ArrayList<>();
for(int i = 0; i < n; i++){
  addName.add(in.nextLine());
}
Posted by: Guest on December-19-2020
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
0

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

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

append to arraylist by index java

arrlist.add(2,25);
// .add(index, content)
Posted by: Guest on June-13-2020

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language