Java ArrayList add elements

Introduction

To Add elements to ArrayList in Java


arrayList.add(your object);

Full source

import java.util.ArrayList; 
 
public class Main { 
  public static void main(String args[]) { 
    // Create an array list. 
    ArrayList<String> al = new ArrayList<String>(); 
     //from ww  w .  j a  v a 2 s.c o m
    // Add elements to the array list. 
    al.add("SQL"); 
    al.add("Java"); 
    al.add("Javascript"); 
    al.add("CSS"); 
    al.add("HTML"); 
    al.add("Demo2s.com"); 
    al.add(1, "Hi"); 
 
    System.out.println("Size of al after additions: " + 
                       al.size()); 
 
 
  } 
}



PreviousNext

Related