Given a string str consisting of a sentence, the task is to find the count of words in the given sentence that end with the given suffix suff.
Input: str = “GeeksForGeeks is a computer science portal for geeks”, suff = “ks”
“GeeksForGeeks” and “geeks” are the only words ending with “ks”.
Input: str = “This is a sample string”, suff = “is”
- Extract all the words from the given sentence using the split() method.
- Now for every word check whether the current words ends with the given suffix using endsWith() method.
Below is the implementation of the above approach:
- Count words that appear exactly two times in an array of words
- Count of distinct substrings of a string using Suffix Array
- Count of distinct substrings of a string using Suffix Trie
- Count words in a given string
- Count of words that are present in all the given sentences
- Count words present in a string
- Count palindrome words in a sentence
- Count the number of words having sum of ASCII values less than and greater than k
- Check if the given string of words can be formed from words present in the dictionary
- Reverse words in a given String in Java
- Find the count of M character words which have at least one character repeated
- Java program to swap first and last characters of words in a sentence
- Java ArrayList to print all possible words from phone digits
- Count of words whose i-th letter is either (i-1)-th, i-th, or (i+1)-th letter of given word
- Counting number of lines, words, characters and paragraphs in a text file using Java
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.