KnowledgeBoat Logo

Computer Applications

The statement used to find the total number of Strings present in the string array String s[] is:

  1. s.length
  2. s.length()
  3. length(s)
  4. len(s)

Java Arrays

ICSE Sp 2025

1 Like

Answer

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:

  1. s.length():
  • Incorrect. The length() method is used for String objects to get the number of characters in a String, not for arrays.
  1. length(s):
  • Incorrect. This is not a valid syntax in Java.
  1. len(s):
  • Incorrect. Java does not have a function called len() for arrays or strings.

Answered By

1 Like


Related Questions