Java ArrayList get ArrayList size before and after remove action

Introduction

To get ArrayList size before and after remove action in Java

arrayList.size();//return the current element count in an array list

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



PreviousNext

Related