Computer Applications
The String method, which results only in a positive integer, is :
- indexOf
- lastIndexOf
- compareTo
- length
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.
Related Questions
Which of the following are Wrapper classes?
(i) Boolean
(ii) boolean
(iii) character
(iv) Character- (i) and (iv)
- (ii) and (iv)
- (i) and (iii)
- (ii) and (iii)
Conversion of a wrapper class to its corresponding primitive type is known as :
- unboxing
- autoboxing
- type casting
- parsing
The method to convert a String to double is:
- String.toDouble()
- Double.Parsedouble()
- Double.parseDouble(String)
- Double.parseDouble()
The java statement System.out.println(x[x.length]) results in:
- logical error
- syntax error
- run time error
- no error