if String is an array of characters,why "length( );" is used to find out its length. Other than "length;" which is used to get length of an array? give answer to the uniqueness of String. | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
+ 1

if String is an array of characters,why "length( );" is used to find out its length. Other than "length;" which is used to get length of an array? give answer to the uniqueness of String.

12th Oct 2016, 10:50 AM
Mihir
2 Antworten
+ 2
Arrays are special object in java having attribute length (which is final and is set at time of array definition ) and array are part of language itself so there is no class definition for array which you can find whereas String class has been defined and its definition can be looked into, String class contains a method length() to retrieve String's length. more detail about array members:-  Array Members The members of an array type are all of the following: The public final field length, which contains the number of components of the array. length may be positive or zero. The public method clone, which overrides the method of the same name in class Object and throws no checked exceptions. The return type of the clone method of an array type T[] is T[]. A clone of a multidimensional array is shallow, which is to say that it creates only a single new array. Sub arrays are shared. All the members inherited from class Object; the only method of Object that is not inherited is its clone method.
12th Oct 2016, 11:22 AM
shivam
shivam - avatar
- 2
sorry I don't know it
12th Oct 2016, 10:59 AM
rahul gautam
rahul gautam - avatar