Try this solution
int index = sent.indexOf(find);
if (index != -1) {
if (index == 0) {
System.out.println("true");
}
else if (index + find.length() == sent.length())
{
System.out.println("true");
}
else if (sent.charAt(index - 1) == ' ' && sent.charAt(find.length() + index) == ' ') {
System.out.println("true");
} else {
System.out.println("false");
}
} else {
System.out.println("false");
}
If you want something more than you original question then instead for checking for spaces you should check that they are not between 0-9 and a-Z, this should cover any characters such as comma period etc.