Java String Search
Chapter:
String Handling
Last Updated:
20-08-2016 18:24:57 UTC
Program:
/* ............... START ............... */
public class JavaStringSearchExample {
public static void main(String[] args) {
String string = "Java Scan";
int intIndex = string.indexOf("Scan");
if (intIndex == -1) {
System.out.println("Scan not found");
} else {
System.out.println("Found Scan at index " + intIndex);
}
}
}
/* ............... END ............... */
Output
Notes:
-
indexOf() method which returns a position index of a word within the string if found.
Tags
String Search, Java