Languages
[Edit]
EN

Java - get ArrayList size

0 points
Created by:
Dirask Community
6810

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

Java Collections - ArrayList

Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join