Advertisement
YankoZlatanov

Untitled

Feb 10th, 2015
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.54 KB | None | 0 0
  1. import java.util.Scanner;
  2. import java.util.TreeSet;
  3.  
  4. public class ExtractAllUniqueWords {
  5.  
  6.     public static void main(String[] args) {
  7.         try (Scanner scanner = new Scanner(System.in)) {
  8.             String[] words = scanner.nextLine().split("\\W+");
  9.             TreeSet<String> orderedWords = new TreeSet<>();
  10.             for (int i = 0; i < words.length; i++) {
  11.                 orderedWords.add(words[i].toLowerCase());
  12.             }
  13.             // print
  14.             for (String word : orderedWords) {
  15.                 System.out.print(word + " ");
  16.             }
  17.         } catch (Exception e) {
  18.             e.printStackTrace();
  19.         }
  20.     }
  21.  
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement