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
🌐
GeeksforGeeks
geeksforgeeks.org › java › list-size-method-in-java-with-examples
List size() method in Java with Examples - GeeksforGeeks
July 11, 2025 - ... // Java program to Illustrate ... l.add(5); // Getting total size of list // using size() method int s = l.size(); System.out.println("Size : " + s); } }...
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
🌐
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 ...
🌐
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 a list that contains 3 lists and then use the Stream API to get the length of each list with their name. import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; public class LengthOfListOfLists { public static void main(String[] ...
🌐
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 ... size Java. The size() method is specific to List implementations and provides a dynamic size that can change as elements are added or removed. On the other hand, the length property is a fixed value for arrays, representing the number of elements that can be stored in the array. Let's explore a few more examples to solidify ...
🌐
TutorialsPoint
tutorialspoint.com › how-to-use-list-size-method-in-java-with-examples
How to use List size() method in Java With Examples?
This is another example of using the size() method to find the length of the list before and after adding the element to it: import java.util.ArrayList; import java.util.List; public class sizeMethod { public static void main(String[] args) { //instantiating a List using ArrayList class List<String> vowels = new ArrayList<>(); System.out.println("List size before adding element to it: " + vowels.size()); //adding element to it vowels.add("A"); vowels.add("E"); vowels.add("I"); vowels.add("O"); vowels.add("U"); System.out.println("The list after adding elements: " + vowels); System.out.println("List size after adding elements to it: " + vowels.size()); } } Below is the output of the above program: List size before adding element to it: 0 The list after adding elements: [A, E, I, O, U] List size after adding elements to it: 5 ·
🌐
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
* */ public class ArrayListDemo{ ... of array list"); ArrayList<String> listOfBanks = new ArrayList<>(); int size = listOfBanks.size(); System.out.println("size of array list after creating: " + size); listOfBanks.add("Citibank"); ...
Find elsewhere
🌐
W3Schools
w3schools.com › java › ref_arraylist_size.asp
Java ArrayList size() Method
HTML Reference CSS Reference JavaScript Reference SQL Reference Python Reference W3.CSS Reference Bootstrap Reference PHP Reference HTML Colors Java Reference AngularJS Reference jQuery Reference · HTML Examples CSS Examples JavaScript Examples How To Examples SQL Examples Python Examples W3.CSS Examples Bootstrap Examples PHP Examples Java Examples XML Examples jQuery Examples
🌐
Scaler
scaler.com › home › topics › java list size()
Java List Size() - Scaler Topics
April 28, 2024 - Java List size() method returns the count of elements present in the ArrayList. For example, if an ArrayList has five string objects stored in it, the size method will return five.
🌐
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 ...ln("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 - Learn to code in Java — a robust programming language used to create software, web and mobile apps, and more. Beginner Friendly.Beginner Friendly17 hours17 hours · Here, a variable size of type int is initialized with the size of a list. The List interface is an ordered collection of elements and is implemented by various classes such as ArrayList, LinkedList, and Vector: ... The following example creates an ArrayList, uses .add() to append elements to it, and uses .size() to print out its size:
🌐
BeginnersBook
beginnersbook.com › 2013 › 12 › how-to-find-length-of-arraylist-in-java
How to find length of ArrayList in Java
Another Example: This is another ... java.util.ArrayList; public class JavaExample { public static void main(String [] args) { ArrayList<String> cityList=new ArrayList<>(); //adding elements to the arraylist cityList.add("Delhi"); cityList.add("Jaipur"); cityList.add("Agra"); ...
🌐
Board Infinity
boardinfinity.com › blog › listsize-in-java
ListSize() in Java | Board Infinity
August 30, 2025 - To avoid it, you can decide whether to verify if the list is empty or not. ... Assume you wish to use the size() method to determine the size of an ArrayList that contains some names. The Java code that follows shows how to build an ArrayList of Strings, add two string objects to it using the add() function, then get the number of entries in the list using the size() method.
🌐
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 not contain any null elements.)
🌐
W3Docs
w3docs.com › java
How to find the length of an array list?
Here is an example of how you can use the size() method to find the length of an ArrayList: List<String> list = new ArrayList<>(); list.add("apple"); list.add("banana"); list.add("orange"); int length = list.size(); // length is 3 ·
🌐
TutorialsPoint
tutorialspoint.com › get-the-size-of-an-arraylist-in-java
Get the Size of an ArrayList in Java
import java.util.ArrayList; import ... aList.add("Mango"); aList.add("Guava"); aList.add("Orange"); aList.add("Peach"); System.out.println("The size of the ArrayList is: " + aList.size()); } }...
🌐
iO Flood
ioflood.com › blog › length-of-arraylist-java
Java ArrayList Length: How to Get the Size of an ArrayList
February 27, 2024 - In Java, you can have an ArrayList of ArrayLists, also known as a multi-dimensional ArrayList. In such cases, finding the length of an individual ArrayList within this structure might be a bit tricky. Let’s look at an example: ArrayList<ArrayList<String>> multiList = new ArrayList<>(); ArrayList<String> list1 = new ArrayList<>(Arrays.asList('Hello', 'World')); ArrayList<String> list2 = new ArrayList<>(Arrays.asList('Java', 'Programming')); multiList.add(list1); multiList.add(list2); for (ArrayList<String> list : multiList) { System.out.println(list.size()); } # Output: # 2 # 2
🌐
Quora
quora.com › What-is-the-best-way-to-find-the-length-of-a-list-in-Java
What is the best way to find the length of a list in Java? - Quora
Answer: To find the length or size of array list in java we can use size() method of java.util.ArrayList The size method returns the integer equal to a number of elements in the list.
🌐
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 ... 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); } }...