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:
xxxxxxxxxx
1
myArrayList.size();
In this example, we create fruits
ArrayList and display its size using size()
method.
xxxxxxxxxx
1
import java.util.ArrayList;
2
3
public class Example {
4
5
public static void main(String[] args) {
6
List<String> fruits = new ArrayList<>();
7
8
fruits.add("Apple");
9
fruits.add("Banana");
10
fruits.add("Cherry");
11
12
System.out.println(fruits.size()); // print ArrayList size
13
}
14
}
Output:
xxxxxxxxxx
1
3