java program to print unique words in a sentence

Solutions on MaxInterview for java program to print unique words in a sentence by the best coders in the world

showing results for - "java program to print unique words in a sentence"
Nina
20 Jun 2019
1import java.util.Arrays;
2import java.util.HashSet;
3 
4/**
5 * Java Program - Find Unique Words
6 */
7public class Example {
8 
9    public static void main(String[] args) {
10 
11        String str = "apple banana mango grape lichi mango apple grape";
12         
13        String[] words = str.split(" ");
14         
15        HashSet<String> uniqueWords = new HashSet<String>(Arrays.asList(words));
16         
17        for(String s:uniqueWords)
18            int i=1;
19            System.out.println(i+". "+s);
20    }
21 
22}
23
similar questions