Good place to look for useful methods associated with List is documentation: https://docs.oracle.com/javase/8/docs/api/java/util/List.html

' size() Returns the number of elements in this list.'

List myList = Arrays.asList(1,2,3,4,5);

myList.size();

Answer from M.Bugiel on Stack Overflow
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
🌐
LeetCode
leetcode.com › problems › copy-list-with-random-pointer
Copy List with Random Pointer - LeetCode
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
🌐
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.
🌐
Chrome Enterprise
chromeenterprise.google › policies
Chrome Enterprise Policy List & Management | Documentation
Chrome Enterprise policies for businesses and organizations to manage Chrome Browser and ChromeOS.
Find elsewhere
🌐
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 ...
🌐
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 ...
🌐
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 ...
🌐
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.
🌐
W3Schools
w3schools.com › java › ref_arraylist_size.asp
Java ArrayList size() Method
compare() equals() sort() fill() length Java ArrayList Methods · add() addAll() clear() clone() contains ensureCapacity() forEach() get() indexOf() isEmpty() iterator() lastIndexOf() listIterator() remove() removeAll() removeIf() replaceAll() retainAll() set() size() sort() spliterator() subList() toArray() trimToSize() Java LinkedList Methods ·
🌐
GeeksforGeeks
geeksforgeeks.org › java › difference-between-length-of-array-and-size-of-arraylist-in-java
Difference between length of Array and size of ArrayList in Java - GeeksforGeeks
July 11, 2025 - Array is static so when we create an array of size n then n blocks are created of array type and JVM initializes every block by default value. Let's see this in the following figure. On the other hand, java ArrayList does not have length property.
🌐
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); } }
🌐
Stack Overflow
stackoverflow.com › questions › 33051787 › how-do-i-find-a-string-lists-length-in-java
arrays - How do I find a String list's length in Java? - Stack Overflow
Did you look at the Javadoc of List? (I assume the compile-time type of results is List<String>.) It's really important that you learn to read the appropriate documentation. Additionally, why have you tagged the question arrays` when your question is about lists rather than arrays? It's important to understand that they're not the same thing. Finally, rather than saying j <= results.length - 1 it would be more idiomatic to write j < results.length.
Top answer
1 of 10
64

Do not come up with a new word. Your name is perfectly fine: It is unambiguous and specific and consequently leaves no doubt to the reader what you are talking about.

By contrast, singleton, unary, 1-tuple or any other term borrowed from mathematics or software engineering carries with it a baggage of preconceptions which are confusing. A list with a single element in it is emphatically not a singleton. It has nothing to do with unary operators, and a list is clearly not a tuple in C++. It is a list with one element in it, not more, not less.

That is sometimes a perceived downside of a simple approach in programming: It seems unsophisticated, and hence of a lesser value. Look at Duff's device! Marvel at the ingenuity of boost.lambda! But then listen to Jim Radigan, who leads the VC++ compiler team:

One of the other things that happen when we go to check code into the compiler is we do peer code review. So if you survive that, it’s probably ok, it’s not too complex. But if you try to check in meta-programming constructs with 4-5 different include files and virtual methods that wind up taking you places you can’t see unless you’re in a debugger – no one is going to let you check that in.

That your peer is able to understand your code right away because it is plain and simple and calls things what they are is not a sign that you didn't realize your full programming potential. It is a sign of excellence. Do not look for a Latin word.

2 of 10
30

There is as far as I know, no widely accepted term in SW engineering to described a list with exactly one element

In mathematics, and more precisely in the set theory, a set with only one element is called a singleton. Unfortunately, in SW engineering, the term is so heavily associated with a design pattern, that using it for another purpose might create a confusion.

Anyway, a list is ordered, so a set is not a list. An ordered list of items is called a sequence in mathematics. And a sequence with exactly one element is called a 1-tuple. Unfortunately, a tuple corresponds to specific data structures, so this term, even converted to letters-only, would also be very ambiguous.

Finally, if mathematics don’t help, let’s look at literature! The contrary of plural is singular. According to the Meriam-Webster dictionary, it means “of, or relating to, one person, thing or instance”. So a singular list should express exactly what you want. This term is even reinforced by its ambiguity: “singular” is associated in other contexts with strangeness, and a list with only one element is indeed a strange list (as πάντα ῥεῖ already pointed out in the comments. But I’d nevertheless prefer to explain it a comment at first use ;-)

🌐
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); } }
🌐
Oreate AI
oreateai.com › blog › understanding-array-length-in-java-a-comprehensive-guide › a0db996741a7af4090cbdd0173062e4c
Understanding Array Length in Java: A Comprehensive Guide - Oreate AI Blog
January 8, 2026 - import java.lang.reflect.Array; numbers = new int[]{1, 2}; integer lenUsingReflection = Array.getLength(numbers); // Also returns 2. directly accessing properties might be more straightforward in most cases though. beyond just retrieving lengths, you might wonder about differences between `.size()` and `.length`. While both serve similar purposes—returning counts—they apply differently across data types: `.size()` is used with collections like Lists or Sets while `.length` pertains strictly to arrays.
🌐
W3Schools
w3schools.com › java › ref_string_length.asp
Java String length() Method
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() method returns the length of a specified string.
🌐
Medium
medium.com › @mswukris › java-length-length-size-349de215ea83
Java — length, length(), size()
April 9, 2023 - import java.util.ArrayList; import java.util.Arrays; public class MyClass { public static void main(String args[]) { int[] arr = new int[5]; System.out.println(arr.length); //5 String str = "Hello World"; System.out.println(str.length()); //11 List<Object> aList = new ArrayList<>(); System.out.println(aList.size()); //0 List<Integer> bList = new ArrayList<>(Arrays.asList(1, 2, 3)); System.out.println(bList.size()); //3 } } 變數 (variable) 有兩種,一種是基本資料型態 (primitive data type) ,另一種則是對物件 (object) 的參考 (reference) Arrays 內可以是 primitive data type 或 object ·
🌐
CodeChef
codechef.com › practice › linked-lists
Linked Lists
Practice these 15 Linked lists problems in languages like C++, Java, Python and JavaScript. These linked list coding questions range from easy to hard difficulty and will prepare you to tackle any linked list question in future.
🌐
TutorialsPoint
tutorialspoint.com › how-to-use-list-size-method-in-java-with-examples
How to use List size() method in Java With Examples?
May 26, 2025 - import java.util.ArrayList; import ... 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() ...