Java ArrayList print out content

Introduction

To print out ArrayList content in Java

System.out.println(arrayListObject); 

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   w w w .j av  a2s  .  c om*/
    // 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()); 
    
    System.out.println(al);
    
    // Remove elements from the array list. 
    al.remove("CSS"); 
    al.remove(2); 
 
    System.out.println("Size of al after deletions: " + 
                       al.size());
    
    System.out.println(al);
  } 
}



PreviousNext

Related