Languages

Java - difference between length and length()

3 points
Asked by:
Geo-Baby
240

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

2 answers
3 points
Answered by:
Geo-Baby
240

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:
Geo-Baby
240

.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
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.

❤️💻 🙂

Join