Just use

int listCount = data.size();

That tells you how many lists there are (assuming none are null). If you want to find out how many strings there are, you'll need to iterate:

int total = 0;
for (List<String> sublist : data) {
    // TODO: Null checking
    total += sublist.size();
}
// total is now the total number of strings
Answer from Jon Skeet on Stack Overflow
๐ŸŒ
W3Schools
w3schools.com โ€บ java โ€บ ref_arraylist_size.asp
Java ArrayList size() Method
Java Data Structures Java Collections Java List Java ArrayList Java LinkedList Java List Sorting Java Set Java HashSet Java TreeSet Java LinkedHashSet Java Map Java HashMap Java TreeMap Java LinkedHashMap Java Iterator Java Algorithms
๐ŸŒ
W3Docs
w3docs.com โ€บ java
How to find the length of an array list?
To find the length (number of elements) of an ArrayList in Java, you can use the size() method of the ArrayList class. Here is an example of how you can use the size() method to find the length of an ArrayList: List<String> list = new ArrayList<>(); ...
People also ask

How does the size() method work in Java Lists?
When you call the size() method on a Java List, it does a little bit of internal magic. Rather than iterating through all elements, it directly accesses a variable or field that keeps track of the number of elements in the List, returning that value to you swiftly.
๐ŸŒ
upgrad.com
upgrad.com โ€บ home โ€บ tutorials โ€บ software & tech โ€บ java list size
Java List Size: Understanding and Utilizing Dynamic Data Structures
Why is the time complexity of the size() method constant?
The efficiency of the size() method is a boon. It boasts a constant time complexity because it merely retrieves the stored size value. It doesn't need to traverse through the List's elements, ensuring a quick and efficient response regardless of the List's size.
๐ŸŒ
upgrad.com
upgrad.com โ€บ home โ€บ tutorials โ€บ software & tech โ€บ java list size
Java List Size: Understanding and Utilizing Dynamic Data Structures
How often should I call the size() method?
The size() method is there for your use anytime you need to know the number of elements in the List. However, using it excessively or unnecessarily could have performance implications, so employ this tool wisely and only when needed.
๐ŸŒ
upgrad.com
upgrad.com โ€บ home โ€บ tutorials โ€บ software & tech โ€บ java list size
Java List Size: Understanding and Utilizing Dynamic Data Structures
๐ŸŒ
W3Schools
w3schools.com โ€บ java โ€บ ref_arrays_length.asp
Java Array length Property
Java Examples Java Videos Java Compiler Java Exercises Java Quiz Java Code Challenges Java Server Java Syllabus Java Study Plan Java Interview Q&A Java Certificate ... The length property returns the length of an array.
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ how-do-i-get-length-of-list-of-lists-in-java
How do I get length of list of lists in Java?
In the below example, we will create 3 lists of lists and then use a for loop to get the length of each list. import java.util.ArrayList; import java.util.List; public class LengthOfListOfLists { public static void main(String[] args){ List<List<Integer>> listOfLists = new ArrayList<>(); List<Integer> list1 = new ArrayList<>(); list1.add(1); list1.add(2); List<Integer> list2 = new ArrayList<>(); list2.add(3); list2.add(4); list2.add(5); List<Integer> list3 = new ArrayList<>(); list3.add(6); listOfLists.add(list1); listOfLists.add(list2); listOfLists.add(list3); for(List<Integer> list : listOfLists) { System.out.println("Length of list: " + list.size()); } } }
๐ŸŒ
W3Schools
w3schools.com โ€บ java โ€บ ref_string_length.asp
Java String length() Method
The length() method returns the length of a specified string. Note: The length of an empty string is 0. ... If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail: sales@w3schools.com
๐ŸŒ
Upgrad
upgrad.com โ€บ home โ€บ tutorials โ€บ software & tech โ€บ java list size
Java List Size: Understanding and Utilizing Dynamic Data Structures
3 weeks ago - In Java, the List interface provides the size() method to retrieve the number of elements in a List, while the length property is used to determine the array size Java. The size() method is specific to List implementations and provides a dynamic ...
Find elsewhere
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ java โ€บ list-size-method-in-java-with-examples
List size() method in Java with Examples - GeeksforGeeks
July 11, 2025 - Return Value: This method returns the number of elements in this list. ... // Java program to Illustrate size() method // of List class for Integer value import java.util.*; public class GFG { public static void main(String[] arg) { // Creating object of ArrayList class List<Integer> l = new ArrayList<Integer>(); // Adding Element l.add(1); l.add(2); l.add(3); l.add(4); l.add(5); // Getting total size of list // using size() method int s = l.size(); System.out.println("Size : " + s); } }
๐ŸŒ
W3Schools
w3schools.com โ€บ java โ€บ ref_linkedlist_size.asp
Java LinkedList size() Method
Java Data Structures Java Collections Java List Java ArrayList Java LinkedList Java List Sorting Java Set Java HashSet Java TreeSet Java LinkedHashSet Java Map Java HashMap Java TreeMap Java LinkedHashMap Java Iterator Java Algorithms
๐ŸŒ
TheServerSide
theserverside.com โ€บ blog โ€บ Coffee-Talk-Java-News-Stories-and-Opinions โ€บ Java-array-size-explained-by-example
Java array size, length and loop examples
Any class that extends the List interface expands dynamically. Java arrays do not expand and contract. You canโ€™t change the size of an array in Java once the array is initialized. A common example of the Java array length property being used in code is a program looping through all of the elements in an array.
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ how-to-use-list-size-method-in-java-with-examples
How to use List size() method in Java With Examples?
import java.util.ArrayList; import java.util.List; public class sizeMethod { public static void main(String[] args) { //instantiating a List using ArrayList class List<Integer> list = new ArrayList<>(); //adding element to it list.add(10); list.add(20); list.add(30); System.out.println("The list elements are: " + list); //using size() method System.out.println("The size of list is: " + list.size()); } } ... This is another example of using the size() method to find the length of the list before and after adding the element to it:
๐ŸŒ
Scaler
scaler.com โ€บ home โ€บ topics โ€บ java list size()
Java List Size() - Scaler Topics
April 28, 2024 - You can check whether the list is null or not to avoid it. Assume you have an ArrayList with some names, and you want to use the size() method to find out how big it is. In the code below, we've created an ArrayList of Strings in Java, added ...
๐ŸŒ
Java67
java67.com โ€บ 2016 โ€บ 07 โ€บ how-to-find-length-size-of-arraylist-in-java.html
How to find length/size of ArrayList in Java? Example | Java67
Since ArrayList is a growable array, it automatically resizes when the size (number of elements in the array list) grows beyond a threshold. Also, when an ArrayList is first created it is called empty ArrayList, and size() will return zero. If you add elements then size grows one by one. You can also remove all elements from ArrayList by using a clear() method which will then again make the ArrayList empty as shown in our examples. Here is our sample Java program to demonstrate how to find the length or size of ArrayList in Java.
๐ŸŒ
W3Schools
w3schools.com โ€บ java โ€บ java_list.asp
Java List
Java Examples Java Videos Java Compiler Java Exercises Java Quiz Java Code Challenges Java Server Java Syllabus Java Study Plan Java Interview Q&A Java Certificate ... The List interface is part of the Java Collections Framework and represents an ordered collection of elements.
๐ŸŒ
Oracle
docs.oracle.com โ€บ javase โ€บ 8 โ€บ docs โ€บ api โ€บ java โ€บ util โ€บ List.html
List (Java Platform SE 8 )
October 20, 2025 - If the list fits in the specified array with room to spare (i.e., the array has more elements than the list), the element in the array immediately following the end of the list is set to null. (This is useful in determining the length of the list only if the caller knows that the list does ...
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ how-do-i-set-the-size-of-a-list-in-java
How do I set the size of a list in Java?
If you try to add an element to this list, it will throw an UnsupportedOperationException because the list is immutable. import java.util.Collections; import java.util.List; public class SetSizeOfList { public static void main(String[] args) { List<Integer> list = Collections.nCopies(5, 0); System.out.println("List of size 5: " + list); // list.add(1); } }
๐ŸŒ
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 - // 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); } }
๐ŸŒ
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.
๐ŸŒ
Board Infinity
boardinfinity.com โ€บ blog โ€บ listsize-in-java
ListSize() in Java | Board Infinity
August 30, 2025 - Understand the listSize() method in Java. Learn syntax, usage, and examples for handling elements in collections.