EN
Java - difference between length and length()
2
answers
3
points
What is the difference between length
and length()
in Java?
2 answers
3
points
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
.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