EN
Java - get ArrayList size
0
points
In this article, we would like to show you how to get ArrayList size in Java.
Quick solution:
myArrayList.size();
Practical example
In this example, we create fruits
ArrayList and display its size using size()
method.
import java.util.ArrayList;
public class Example {
public static void main(String[] args) {
List<String> fruits = new ArrayList<>();
fruits.add("Apple");
fruits.add("Banana");
fruits.add("Cherry");
System.out.println(fruits.size()); // print ArrayList size
}
}
Output:
3