Hlo. You can split the sentence as array and then you put into List. after that you can use contains method to check you word is present or not. Kindly try this code..
import java.util.ArrayList;
import java.util.Arrays;
public class karthitest {
public static void main(String[] args) {
String sentence = "I am Karthick";
String word = "I";
if(isWordExist(sentence, word)){
System.out.println("Word is exist");
}
}
public static boolean isWordExist(String sentence, String word){
boolean ans = Boolean.FALSE;
ArrayList wordList = null;
try {
if(sentence != null && word != null){
wordList = new ArrayList(Arrays.asList(sentence.split("[^a-zA-z]+")));
if(wordList.contains(word)){
ans = Boolean.TRUE;
}
}
} catch (Exception e) {
e.printStackTrace();
// TODO: handle exception
}
return ans;
}
}