Yes, .length (property-like, not a method):

String[] array = new String[10];
int size = array.length;
Answer from Kris on Stack Overflow
🌐
W3Schools
w3schools.com › java › ref_arrays_length.asp
Java Array length Property
This is a built-in Java property, and does not belong to the Java Arrays Class. Note: The length property must not be mistaken with the length() method that is used for Strings.
Discussions

Java - How do I find the length of a string in an array? - Stack Overflow
All I need to know is how to find the length of the string inside of the array. I also would like to know how to find which string comes first in alphabetical order in the array. More on stackoverflow.com
🌐 stackoverflow.com
arrays - length and length() in Java - Stack Overflow
In the first case (20-25) the code ... of the array (in JNI this would have been a call to GetArrayLength()) whereas in the String case (28-35) it needs to do a method call to get the length. In the mid 1990s, without good JITs and stuff, it would have killed performance totally to only have the java.util.Vector ... More on stackoverflow.com
🌐 stackoverflow.com
How do I specify the length of strings in a list of strings ?
Please ensure that: Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions You include any and all error messages in full You ask clear questions You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions. Trying to solve problems on your own is a very important skill. Also, see Learn to help yourself in the sidebar If any of the above points is not met, your post can and will be removed without further warning. Code is to be formatted as code block (old reddit: empty line before the code, each code line indented by 4 spaces, new reddit: https://imgur.com/a/fgoFFis ) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc. Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit. Code blocks look like this: public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); } } You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above. If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures. To potential helpers Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice. I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns. More on reddit.com
🌐 r/javahelp
3
1
August 4, 2021
How to find out the length of an array in Java
Yeah, I see your point, I was actually ... that on Strings too. ... That wonderful valley when you know the language just enough to not notice the flaws in the joke. ... out of curiosity, what are the flaws? (what's wrong with the code or in what way doesn't it work). obviously there is some built-in way to get the array length, I'm asking about the flaws in the joke as written - (other than taking O(n) to return the length.)? I don't know Java at ... More on reddit.com
🌐 r/ProgrammerHumor
183
3830
November 12, 2017
🌐
GeeksforGeeks
geeksforgeeks.org › java › length-vs-length-java
length vs length() in Java - GeeksforGeeks
January 4, 2025 - The length() method returns the number of characters present in the string. ... 1. The length variable is applicable to an array but not for string objects whereas the length() method is applicable for string objects but not for arrays.
🌐
HappyCoders
happycoders.eu › home › java › java array length and size: .length, 2d arrays, max array size
Java Array Length and Size: .length, 2D Arrays, Max Array Size
September 25, 2026 - For the other arrays in this section, JOL also measures the calculated sizes: 24 bytes for the short and the byte array, 40 bytes for the long array with three elements, 56 bytes for the one with five, and 32 bytes for the String array.
🌐
TheServerSide
theserverside.com › blog › Coffee-Talk-Java-News-Stories-and-Opinions › Java-length-vs-length-Whats-the-difference
Java length vs length(): What's the difference?
See how Java handles array sizes and String character counts, why the syntax differs, and which compile errors result from mixing them up. ... The key difference between an array’s length field and Java’s length() method is that the array length field describes the size of an array, while Java’s length() method tells you how many characters a text String contains.
Published: February 3, 2026
🌐
Codecademy
codecademy.com › docs › java › arrays › .length
Java | Arrays | .length | Codecademy
April 21, 2025 - In Java, the .length property is used to determine the length or size of an array. It is a built-in property for arrays and returns an integer value that represents the number of elements in the array.
🌐
Medium
medium.com › javarevisited › understanding-java-arrays-from-basics-to-length-and-limits-9c30f749f2fd
Understanding Java Arrays: From Basics to Length and Limits | by sajith dilshan | Javarevisited | Medium
August 25, 2025 - In Java, though, arrays don’t have a size() method. Instead, they come with a built-in length property that tells you how many elements they can hold. ... char[] gradeLevels = {'A', 'B', 'C'}; System.out.println("Number of grades: " + gradeLevels.length); ... Here’s a common beginner mistake: arrays use a property called .length, while Strings use a method called .length().
Find elsewhere
🌐
Software Testing Help
softwaretestinghelp.com › home › java tutorial for beginners: 100+ hands-on java video tutorials › java array length tutorial with code examples
Java Array Length Tutorial With Code Examples
April 1, 2025 - Answer: The ‘length’ property is a part of the array and returns the size of the array. The method length() is a method for the string objects that return the number of characters in the string.
🌐
Great Learning
mygreatlearning.com › blog › it/software development › how to find array length in java
How to find Array Length in Java
September 12, 2024 - So, if you want to find the length of characters in a string, you need to use the length() method, whereas if you want to find the length or size of an array, you must use the length attribute of Java.
🌐
JanBask Training
janbasktraining.com › home › difference between array length vs string length () function in java
Difference between Array Length vs String Length () Function in Java
February 28, 2024 - In Java, String class has a function that is known as String length that is used to know the length of the String that is stored in the string array. Here the string that has the length of 16-bit Unicode can be identified by the function and ...
🌐
Upgrad
upgrad.com › home › tutorials › software & tech › array length in java
Java Array Length with Examples & Syntax
June 4, 2025 - JavaScript, where array length can change dynamically, Java arrays have a fixed length once declared. ... Explanation: The array marks holds 4 elements, so marks.length returns 4. Note that length is a property, not a method. ... Remember: there are no parentheses because length is a field, not a method. ... String[] cities = {"Delhi", "Mumbai", "Chennai"}; System.out.println("Total Cities: " + cities.length);
🌐
Edureka
edureka.co › blog › string-array-in-java
Java String Array | String Array in Java with Examples | Edureka
July 5, 2024 - An array is a fundamental and crucial data structure Java programming language. It is highly used by programmers due to its efficient and productive nature. A Java String Array is an object that holds a fixed number of String values.
🌐
TheServerSide
theserverside.com › blog › Coffee-Talk-Java-News-Stories-and-Opinions › How-do-I-find-the-Java-array-length
How do I find the Java array length?
The Java array length property does not have round brackets after the field. The Java String length() method does.
Published: June 9, 2025
🌐
TheServerSide
theserverside.com › blog › Coffee-Talk-Java-News-Stories-and-Opinions › Java-array-size-explained-by-example
Java array size, length and loop examples
The length property tells you the Java array size. It is not a method. To further confuse matters, the String class does have a length() method.
Published: July 4, 2026
Top answer
1 of 8
137

Let me first highlight three different ways for similar purpose.

length -- arrays (int[], double[], String[]) -- to know the length of the arrays

length() -- String related Object (String, StringBuilder, etc) -- to know the length of the String

size() -- Collection Object (ArrayList, Set, etc) -- to know the size of the Collection

Now forget about length() consider just length and size().

length is not a method, so it completely makes sense that it will not work on objects. It only works on arrays.
size() its name describes it better and as it is a method, it will be used in the case of those objects who work with collection (collection frameworks) as I said up there.

Now come to length():
String is not a primitive array (so we can't use .length) and also not a Collection (so we cant use .size()) that's why we also need a different one which is length() (keep the differences and serve the purpose).

As answer to Why?
I find it useful, easy to remember and use and friendly.

2 of 8
28

A bit simplified you can think of it as arrays being a special case and not ordinary classes (a bit like primitives, but not). String and all the collections are classes, hence the methods to get size, length or similar things.

I guess the reason at the time of the design was performance. If they created it today they had probably come up with something like array-backed collection classes instead.

If anyone is interested, here is a small snippet of code to illustrate the difference between the two in generated code, first the source:

public class LengthTest {
  public static void main(String[] args) {
    int[] array = {12,1,4};
    String string = "Hoo";
    System.out.println(array.length);
    System.out.println(string.length());
  }
}

Cutting a way the not so important part of the byte code, running javap -c on the class results in the following for the two last lines:

20: getstatic   #3; //Field java/lang/System.out:Ljava/io/PrintStream;
23: aload_1
24: arraylength
25: invokevirtual   #4; //Method java/io/PrintStream.println:(I)V
28: getstatic   #3; //Field java/lang/System.out:Ljava/io/PrintStream;
31: aload_2
32: invokevirtual   #5; //Method java/lang/String.length:()I
35: invokevirtual   #4; //Method java/io/PrintStream.println:(I)V

In the first case (20-25) the code just asks the JVM for the size of the array (in JNI this would have been a call to GetArrayLength()) whereas in the String case (28-35) it needs to do a method call to get the length.

In the mid 1990s, without good JITs and stuff, it would have killed performance totally to only have the java.util.Vector (or something similar) and not a language construct which didn't really behave like a class but was fast. They could of course have masked the property as a method call and handled it in the compiler but I think it would have been even more confusing to have a method on something that isn't a real class.

🌐
Alvin Alexander
alvinalexander.com › java › java-array-length-example-length-method
A Java array length example | alvinalexander.com
August 4, 2024 - While you might logically expect there to be a length method on a Java array, there is actually a public length attribute on an array (instead of a length method).
🌐
Upgrad
upgrad.com › home › tutorials › software & tech › string length in java
String length() Method in Java – Syntax, Example & Use Cases
April 30, 2025 - To find the number of elements in a String array, use the .length property without parentheses.
🌐
GeeksforGeeks
geeksforgeeks.org › java › how-to-find-length-or-size-of-an-array-in-java
How to Find Length or Size of an Array in Java? - GeeksforGeeks
length property works for all array types (int[] , String[], double[]) etc. When iterating over an array, we can also determine its size manually. Example: This example, demonstrates how to use for each loop to calculate the length of an array. Java ·
Published: July 12, 2025