1(xviii)
The statement used to find the total number of Strings present in the string array String s[] is:
- (a)s.length
- (b)s.length()
- (c)length(s)
- (d)len(s)
Show SolutionHide Solution↓
s.length
Reason — In Java, arrays have a property called length, which gives the total number of elements in the array. This applies to any type of array, including arrays of Strings.
For a string array String s[], the correct way to get the number of elements is:
s.length
Analysing other options:
s.length():- Incorrect. The
length()method is used for String objects to get the number of characters in a String, not for arrays.
- Incorrect. The
length(s):- Incorrect. This is not a valid syntax in Java.
len(s):- Incorrect. Java does not have a function called
len()for arrays or strings.
- Incorrect. Java does not have a function called