String a = "Hello my name is Sap";
String b = "HelloisSapmyname";
String c = "Sap is my name";
String d = "Sap";
String keyword = "Sap";
when I use .contains()
it is true for all strings.
How do it get it true for all cases except b?
Note: Adding a space before keyword will not work if the keyword if the first word. Please Help!
EDIT: Added all the possible conditions
SOLUTION: With help from the other answers I found the solution which satisfies every condition
if (a.contains(" "+key+ " ") || a.startsWith(key+" ")
|| a.equals(key) || a.endsWith(" "+key))
Will regex be faster than this?