Check if a word is present in a sentence | Java implementation of the approach ; Function that returns true if the word is found ; To convert the word in uppercase ; To convert the complete sentence in uppercase ; To break the sentence in words ; To store the individual words of the sentence ; Comparing the current word with the word to be searched ; Driver code
import java . util . * ; class GFG { static boolean isWordPresent ( String sentence , String word ) { word = transform ( word ) ; sentence = transform ( sentence ) ; String [ ] s = sentence . split ( " ▁ " ) ; for ( String temp : s ) { if ( temp . compareTo ( word ) == 0 ) { return true ; } } return false ; } static String transform ( String word ) { return word . toUpperCase ( ) ; } public static void main ( String [ ] args ) { String s = " Geeks ▁ for ▁ Geeks " ; String word = " geeks " ; if ( isWordPresent ( s , word ) ) System . out . print ( " Yes " ) ; else System . out . print ( " No " ) ; } }