Skip to content

Java ArrayList length example

Java ArrayList length example shows how to get the length of the ArrayList. The example also shows how to get size or length of an ArrayList using the size method.

How to get ArrayList length in Java (ArrayList size)?

To get the length of the ArrayList, use the size method of ArrayList.

This method returns number of elements in the ArrayList. It returns 0 if the ArrayList is empty.

Example

Output

You can use the size method to get the number of elements contained in the ArrayList and loop through them as given below.

Output

This example is a part of the Java ArrayList tutorial.

Please let us know your views in the comments section below.

About the author

Leave a Reply

Your email address will not be published.