Using the inbuilt "indexOf" method, the word inside a String can be found. In the given example I'm trying to find the "Hello" from the String.
Output:
Found Hello at index 0
public class SearchString{
public static void main(String[] args) {
String strOrig = "Hello readers";
int intIndex = strOrig.indexOf("Hello");
if(intIndex == - 1){
System.out.println("Hello not found");
} else {
System.out.println("Found Hello at index "
+ intIndex);
}
}
}
Output:
Found Hello at index 0
No comments:
Post a Comment