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

Popular posts from this blog

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

html - How to style widget with post count different than without post count -

url rewriting - How to redirect a http POST with urlrewritefilter -