Java: Discover if a word is present in a string -
i want find out if string precise word, example if way:
string s1="welcome"; string s ="welcomes tutorialspoint.com"; system.out.println(s.contains(s1)); it returns true, want give me false, because in variable s word welcomes , not word welcome of s1. how proceed?
you can use
arrays.aslist(s.split("\\s+")).contains(s1) you can modify solution fit needs adapting regex used splitting. instance, if wanted split on isn't word character (i.e. punctuation , whatnot), use \w+.
Comments
Post a Comment