The size member function.

myList.size();

http://docs.oracle.com/javase/6/docs/api/java/util/ArrayList.html

Answer from Adam Reed on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › java › java-program-to-find-the-length-size-of-an-arraylist
Java Program to Find the Length/Size of an ArrayList - GeeksforGeeks
July 11, 2025 - This method does not take any parameters and returns an integer value which is the size of the ArrayList. ... // Java program to find the size // of an ArrayList import java.util.*; public class GFG { public static void main(String[] args) throws Exception { // Creating object of ArrayList<Integer> ArrayList<Integer> arrlist = new ArrayList<Integer>(); // Populating arrlist arrlist.add(1); arrlist.add(2); arrlist.add(3); arrlist.add(4); arrlist.add(5); // print arrlist System.out.println("ArrayList: " + arrlist); // getting total size of arrlist // using size() method int size = arrlist.size(); // print the size of arrlist System.out.println("Size of ArrayList = " + size); } }
🌐
W3Schools
w3schools.com › java › ref_arraylist_size.asp
Java ArrayList size() Method
assert abstract boolean break byte case catch char class continue default do double else enum exports extends final finally float for if implements import instanceof int interface long module native new package private protected public return requires short static super switch synchronized this throw throws transient try var void volatile while Java String Methods · charAt() codePointAt() codePointBefore() codePointCount() compareTo() compareToIgnoreCase() concat() contains() contentEquals() copyValueOf() endsWith() equals() equalsIgnoreCase() format() getBytes() getChars() hashCode() indexOf() isEmpty() join() lastIndexOf() length() matches() offsetByCodePoints() regionMatches() replace() replaceAll() replaceFirst() split() startsWith() subSequence() substring() toCharArray() toLowerCase() toString() toUpperCase() trim() valueOf() Java Math Methods
Discussions

how to set a maximum size for ArrayList?
Use an if statement and the size() of the ArrayList. More on forum.processing.org
🌐 forum.processing.org
May 20, 2013
[JAVA] Why is my ArrayList size always 0
Your ArrayList contains 0 elements, so the size is 0. Your top is also initially -1, so the expression top == stack.size() - 1 will evaluate to -1 == 0 - 1, which is always true (until something is added to the stack). You may be confusing size (number of elements in the current ArrayList) with the capacity (maximum number of elements allowed in the current ArrayList). In any case, if you're trying to write a stack for learning purposes, you'd probably get more out of it if you implemented it on a more basic level, and used an array internally instead of an ArrayList which basically has already implemented most of the logic for you. Alternatively, if you just need a stack, you should probably use java.util.Stack instead of re-implementing one. More on reddit.com
🌐 r/learnprogramming
7
5
February 26, 2017
[Java] How to write .size() method for an ArrayList?
Look ar ArrayList's implementation, create your own class, and implement the most useful methods(add,get,remove,size). It should be pretty straightforward. As you'll see, there is a private variable size, that increases and decreases when you add/remove an object. More on reddit.com
🌐 r/learnprogramming
16
7
April 30, 2013
Java: Is Arraylist better than Arrays?
The biggest difference is that you can add to and remove from a list, whereas arrays have a fixed size. More on reddit.com
🌐 r/learnprogramming
28
19
June 23, 2024
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › util › ArrayList.html
ArrayList (Java Platform SE 8 )
October 20, 2025 - This class is a member of the Java Collections Framework. ... Constructs an empty list with the specified initial capacity. ... Constructs an empty list with an initial capacity of ten. ... Constructs a list containing the elements of the specified collection, in the order they are returned by the collection's iterator. ... Trims the capacity of this ArrayList instance to be the list's current size.
🌐
GeeksforGeeks
geeksforgeeks.org › java › arraylist-size-method-in-java-with-examples
ArrayList size() Method in Java with Examples - GeeksforGeeks
July 11, 2025 - Example 2: Here, we use the size() method to get the number of elements in an ArrayList of strings. ... // Java program to demonstrate the use of // size() method for String ArrayList import java.util.ArrayList; public class GFG { public static ...
🌐
BeginnersBook
beginnersbook.com › 2013 › 12 › how-to-find-length-of-arraylist-in-java
How to find length of ArrayList in Java
September 11, 2022 - You can find the length (or size) of an ArrayList in Java using size() method.
🌐
iO Flood
ioflood.com › blog › length-of-arraylist-java
Java ArrayList Length: How to Get the Size of an ArrayList
February 27, 2024 - It directly gives you the number of elements in the ArrayList, making it a quick and reliable way to find its length. While the size() method is handy, it’s important to remember that it returns the number of elements in the ArrayList, not the capacity. The capacity of an ArrayList refers to the amount of memory allocated for storing elements, regardless of whether those positions are currently holding elements or not. If you’re interested in the capacity, you’ll need to use different techniques, which we’ll cover in the advanced section. In Java, you can have an ArrayList of ArrayLists, also known as a multi-dimensional ArrayList.
Find elsewhere
🌐
TheServerSide
theserverside.com › blog › Coffee-Talk-Java-News-Stories-and-Opinions › Java-array-size-explained-by-example
Java array size, length and loop examples
To get the size of an ArrayList, you use the size() method. Know the difference between the Java array length and the String’s length() method.
🌐
TutorialsPoint
tutorialspoint.com › get-the-size-of-an-arraylist-in-java
Get the Size of an ArrayList in Java
The size of an ArrayList can be obtained by using the java.util.ArrayList.size() method as it returns the number of elements in the ArrayList i.e.
🌐
Quora
quora.com › What-is-the-difference-between-length-of-array-and-size-of-ArrayList-in-Java
What is the difference between length() of array and size() of ArrayList in Java? - Quora
For arrays the length is fixed at creation; array.length is constant for that instance. ... Arrays and ArrayLists both hold collections of elements in Java, but they expose their element count through different methods (or operators) because they are different types.
🌐
Coderanch
coderanch.com › t › 552836 › java › find-size-occupied-arraylist-kilobytes
to find the size occupied by arraylist in kilobytes - i want to find the size of an arraylist (Java in General forum at Coderanch)
September 16, 2011 - You need to send the items in the array list in a serialized of buffered way and that can not be larger than 4 Mb? If you REALLY want to know the byte size of an object, the "trick" is to convert it to an byte[] and look at the size of it. That is done like this: NOTE: This is serialized object ...
🌐
Vultr
docs.vultr.com › java › standard-library › java › util › ArrayList › size
Java ArrayList size() - Get List Size | Vultr Docs
November 13, 2024 - The size() method in Java's ArrayList class is an essential tool for managing collections. It determines the number of elements stored in an ArrayList, which is crucial for operations such as iteration, condition checks, and data manipulation within the list.
🌐
Reddit
reddit.com › r/learnprogramming › [java] why is my arraylist size always 0
r/learnprogramming on Reddit: [JAVA] Why is my ArrayList size always 0
February 26, 2017 -

I've been trying for a while now but I still can't figure out why my arraylist size is always 0. My isFull method always returns true.

public class MyStack<T> {

private ArrayList<T> stack;
private int top;

public MyStack() {
    stack = new ArrayList<T>(50);
    top = -1;
}

public boolean isEmpty() {
    return (top == -1);
}

public boolean isFull() {
    return (top == stack.size() - 1);
}

}

🌐
Quora
quora.com › What-is-the-default-size-of-ArrayList-in-Java
What is the default size of ArrayList in Java? - Quora
Answer (1 of 3): The Default Size of ArrayList is 10 . Once ArrayList reaches its capacity a new ArrayList will be created with new capacity = ( current capacity * 3 /2 ) + 1 . Advantage : Array List is the Best Choice for Retrieval Operations ...
🌐
TutorialsPoint
tutorialspoint.com › home › java/util › java arraylist size
Java ArrayList Size
September 1, 2008 - The following example shows the usage of Java ArrayList size() method. We're adding couple of Integers to the ArrayList object using add() method calls per element. Size of the arraylist is printed using size() method.
🌐
Baeldung
baeldung.com › home › java › java array › the capacity of an arraylist vs the size of an array in java
The Capacity of an ArrayList vs the Size of an Array in Java | Baeldung
November 11, 2025 - We’ll also look at examples of when we should initialize ArrayList with a capacity and the benefits and disadvantages in terms of memory usage. To understand the differences, let’s first try both options. In java, it’s mandatory to specify the size of an array while creating a new instance of it: Integer[] array = new Integer[100]; System.out.println("Size of an array:" + array.length);
🌐
Codecademy
codecademy.com › docs › java › arraylist › .size()
Java | ArrayList | .size() | Codecademy
January 27, 2023 - The .size() method of the ArrayList class returns the number of elements in the list. ... Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more! ... Learn to code in Java — a robust programming language used to create software, web and mobile apps, and more.