State the purpose and return data type of the following String functions:
Views 14
Answer:
(i) indexOf(char ch)
- Purpose: This function returns the index of the first occurrence of the specified character
ch
in the string. If the character is not found, it returns-1
. - Return Data Type:
int
(ii) compareTo(String s)
- Purpose: This function compares two strings lexicographically. It returns a positive integer if the calling string is lexicographically greater than the specified string
s
, a negative integer if it is less, and0
if both strings are equal.
Related Articles:
This section is dedicated exclusively to Questions & Answers. For an in-depth exploration of Java Programming Language, click the links and dive deeper into this subject.
Join Our telegram group to ask Questions
Click below button to join our groups.