Write a function that takes a String as argument and prints all unique words in it.
Input : Java is great. Grails is also great Output : Java Grails also
The idea is to use map to keep track of words already occurred. But first we have to extract all words from a String, as a string may contain many sentences with punctuation marks.
For extracting words from a String, refer Extracting each word from a String.
Python : The idea is to use Dictionary for calculating the count of each word.But first we have to extract all words from a String, as a string may contain many sentences. The word which has count 1 in dictionary is unique word.
Java Grails also
This article is contributed by Gaurav Ahirwar and Gaurav Miglani . 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 write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
- Java program to print Even length words in a String
- Print number of words, vowels and frequency of each character
- Reverse words in a given String in Java
- Print all possible ways to convert one string into another string | Edit-Distance
- Print first letter of each word in a string using regex
- PrintWriter print(String) method in Java with Examples
- PrintStream print(String) method in Java with Examples
- Count of words ending at the given suffix in Java
- Maximum number of Unique integers in Sub-Array of given size
- Java program to swap first and last characters of words in a sentence
- Remove duplicate words from Sentence using Regular Expression
- Swap corner words and reverse middle characters
- Counting number of lines, words, characters and paragraphs in a text file using Java
- Find the count of M character words which have at least one character repeated
- Convert a List of String to a comma separated String in Java
Improved By : Ronit_shrivastava