Since you want to search a word there are three cases:
- word at start of sentence means no space at start but space at end.
- word between the sentence space at both ends.
- word at end only space at end.
To cover all the three cases, one possible solution is:
String str = "I am a JAVA programmer";
String[] splited = str.split("\\b+"); //split on word boundries
Arrays.asList(splited).contains("ram"); //search array for word
Here is working Demo