Yeah i know that we use the .length keyword for counting the number of elements in an array, but actually the .length is. we all know that Java is an object oriented language which means whatever the thing that we talk about is an object.we know that we use the .length() method that is defined in the String class for counting the number of characters in a string object, but where the .length key word for arrays are defined in.
Asked
Active
Viewed 57 times
0
-
You're asking for the source for arrays? – Carcigenicate Oct 01 '19 at 15:27
-
I mean the length() method is defined in the String class, but where the .length key word is defined in. – Hashan Mahesh Oct 01 '19 at 15:31
-
Java being an object oriented language does not mean everything is an object. `length` itself is a _primitive_ field of the respective array, while `length()` would be a _method_ of the `String` class. – Thomas Oct 01 '19 at 15:31
1 Answers
1
Arrays in Java are also classes and their instances are objects. Of course that's a special kind of Objects but as all other objects they have public fields and methods and length
is a public field.
Also array class is extending Object class and have all methods from it like equals()
, hashCode()
, toString()
etc.

Alexey Usharovski
- 1,404
- 13
- 31
-
1Yeah that is my question. we use two brackets to indicate a method, but with the length key word we use nothing for arrays. – Hashan Mahesh Oct 01 '19 at 15:35
-
1
-