Java - difference between length and length()

3 points
Asked by:

What is the difference between length and length() in Java?

2 answers
3 points
Answered by:

1. length

array.length - final variable applicable for arrays that tells us what is the size of the array.

2. length()

string.length() - a method which is applicable for string object, that returns the number of characters in the string.

0 comments Add comment
1 points
Answered by:

.length - built-in field (array length):

String array = new String[5];        // new char[5], new int[5], etc.

System.out.println(array.length);    // 5

.length() - public method (String length, etc.):

String string = "12345";

System.out.println(string.length());  // 5 
0 comments Add comment
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂