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
Why is the size of a List different from its capacity?
Size and capacity may seem interchangeable, but in the context of a Java List, they convey distinct concepts. The size refers to the actual count of elements in the List, while capacity indicates how many elements it can house before needing to resize. Understanding this distinction helps manage lists more effectively.
🌐
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_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
🌐
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 ...
🌐
Upgrad
upgrad.com › home › tutorials › software & tech › java list size
Java List Size: Understanding and Utilizing Dynamic Data Structures
3 weeks ago - 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 our understanding of the Java List 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 ...
Find elsewhere
🌐
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 ...
🌐
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-get-length-of-list-of-lists-in-java
How do I get length of list of lists in Java?
June 5, 2025 - 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()); } } }
🌐
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)
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 ...
🌐
Oracle
docs.oracle.com › en › java › javase › 21 › docs › api › java.base › java › util › List.html
List (Java SE 21 & JDK 21)
January 20, 2026 - 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 ...
🌐
Vultr
docs.vultr.com › java › standard-library › java › util › ArrayList › size
Java ArrayList size() - Get List Size | Vultr Docs
November 13, 2024 - Add some elements to the list. Use the size() method to retrieve the number of elements. ... import java.util.ArrayList; public class Main { public static void main(String[] args) { ArrayList<String> list = new ArrayList<>(); list.add("Apple"); ...
🌐
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?
June 10, 2025 - The size of the list will grow dynamically as elements are added. The syntax for creating an ArrayList with a specific size is as follows: ... We should use index > 0 to add an element, otherwise you will get an IndexOutOfBoundsException as the index will be out of range, considering size is ...
🌐
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 - Integer[] array = new Integer[100]; System.out.println("Size of an array:" + array.length); Here, we created an Integer array of size 100, which resulted in the below output ... Technically, the default capacity (DEFAULT_CAPACITY) of a newly created ArrayList is 10. However, Java 8 changed how this initial capacity is used for performance reasons. It’s not used immediately and is guaranteed lazily once a new item is added to the list.
🌐
iO Flood
ioflood.com › blog › length-of-arraylist-java
Java ArrayList Length: How to Get the Size of an ArrayList
February 27, 2024 - In this example, we create an ArrayList list and add a single element ‘Hello’ to it. Then, we use the size() method to find the length of the ArrayList, which is 1 in this case. The size of the ArrayList is printed to the console.
🌐
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 ...
🌐
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); } }
🌐
W3Schools
w3schools.com › java › java_arraylist.asp
Java ArrayList
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 · Java Wrapper Classes Java Generics Java Annotations Java RegEx Java Threads Java Lambda Java Advanced Sorting ... How Tos Add Two Numbers Swap Two Variables Even or Odd Number Reverse a Number Positive or Negative Square Root Area of Rectangle Celsius to Fahrenheit Sum of Digits Check Armstrong Num Random Number Count Words Count Vowels in a String Remove Vowe