Guest User

Untitled

a guest
May 24th, 2014
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.62 KB | None | 0 0
  1. import java.util.Scanner;
  2. import java.util.Set;
  3. import java.util.TreeSet;
  4. import java.util.regex.Matcher;
  5. import java.util.regex.Pattern;
  6.  
  7.  
  8. public class _10_ExtractAllUniqueWords {
  9.  
  10.     public static void main(String[] args) {
  11.        
  12.         Scanner sc = new Scanner(System.in);
  13.        
  14.         String input = sc.nextLine().toLowerCase();
  15.        
  16.         Pattern regex = Pattern.compile("\\w+");
  17.         Matcher matcher = regex.matcher(input);
  18.         Set<String> uniqueWords = new TreeSet<String>();
  19.        
  20.         while(matcher.find()){
  21.             uniqueWords.add(matcher.group());
  22.         }
  23.        
  24.         for(String element : uniqueWords){
  25.             System.out.print(element + " ");
  26.         }
  27.     }
  28.  
  29. }
Advertisement
Add Comment
Please, Sign In to add comment