+ 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 Answers
+ 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