Multiple choice

Which of the following methods is used to get the index within the given string “str” at the first occurrence of the specified substring “str1”?

  1. str1.indexOf(int ch,int from Index)

  2. str1.indexOf(String str)

  3. str.indexOf(string str1)

  4. str.indexOf(String str1)

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

The method indexOf() is used to get the index within the given string “str” at the first occurrence of the specified substring “str1”. Hence, the statement will be str.indexOf(String str1);