Home / Questions / (vi)(a) Name one String method which results in a positive integer only. (b) Name one String method which results in a character.
Explanatory Question

(vi)
(a) Name one String method which results in a positive integer only.
(b) Name one String method which results in a character.

👁 43 Views
📘 Detailed Answer
🕒 Easy to Read
Read the answer carefully and go through the related questions on the right side to improve your understanding of this topic.

Answer with Explanation

Solution:

(a) A String method that results in a positive integer only:
length() → This method returns the length of the string as a positive integer.
Example:


String str = "Hello";
System.out.println(str.length()); // Output: 5

(b) A String method that results in a character:
charAt(int index) → This method returns the character at the specified index.
Example:


String str = "Hello";
System.out.println(str.charAt(1)); // Output: 'e'