12
Dec
Method to found match word is: String.contains();
public static void main(String[] args) {
String sentence="Hello Java";
String findString = "Java";
Boolean found=sentence.contains(findString);
if(found){
System.out.println("String found");
}
else{
System.out.println("String not found");
}
}
Output:
Hello Java
Type a word to search:
C#
String not found
Java
String found
Leave a Reply