Computer Applications

The String method, which results only in a positive integer, is :

  1. indexOf
  2. lastIndexOf
  3. compareTo
  4. length

Java String Handling

2 Likes

Answer

length

Reason — The length() method of the String class returns the number of characters in the string as a positive integer. Other methods like indexOf and lastIndexOf return the position of a character or substring, which can be -1 if not found, and compareTo returns an integer that can be positive, negative, or zero depending on lexicographical comparison.

Answered By

1 Like


Related Questions