Languages
[Edit]
EN

Java - get ArrayList size

0 points
Created by:
Tomeriko
413

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

Alternative titles

  1. Java - print ArrayList size
  2. Java - get ArrayList length
  3. Java - how to find length of ArrayList
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

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