In this example we will show the method to get the size of an ArrayList in Java.
Source Code
package com.beginner.examples;
import java.util.ArrayList;
public class ArrayListSize {
public static void main(String[] args) {
ArrayList arrays = new ArrayList();
arrays.add("a");
arrays.add("b");
System.out.println(arrays.size()); // get the size of an ArrayList
}
}
Output:
2
References
Imported packages in Java documentation: