169k views
4 votes
What method of the String object searches the string for an occurence of the specified search string?

the charAt() method

the search() method

the indexOf() method

the substring() method

1 Answer

1 vote

Answer:

the indexOf() method

Step-by-step explanation:

The indexOf() method in java returns the first occurrence of the of the string or a character specified in it.It can be used to search both a character or a string.

for example:-

import java.util.*;

import java.lang.*;

import java.io.*;

class indexOf

{

public static void main (String[] args)

{

String s="IamNumber4";

int l=s.indexOf("Num");//using indexOf() method on string object..

System.out.println(l);

}

}

Output:-

3

User Avladov
by
7.4k points

No related questions found