Answers for "java program to print unique words in a sentence"

0

java program to print unique words in a sentence

import java.util.Arrays;
import java.util.HashSet;
 
/**
 * Java Program - Find Unique Words
 */
public class Example {
 
    public static void main(String[] args) {
 
        String str = "apple banana mango grape lichi mango apple grape";
         
        String[] words = str.split(" ");
         
        HashSet<String> uniqueWords = new HashSet<String>(Arrays.asList(words));
         
        for(String s:uniqueWords)
            int i=1;
            System.out.println(i+". "+s);
    }
 
}
Posted by: Guest on March-09-2021

Code answers related to "java program to print unique words in a sentence"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language