Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- import java.util.Set;
- import java.util.TreeSet;
- import java.util.regex.Matcher;
- import java.util.regex.Pattern;
- public class _10_ExtractAllUniqueWords {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- String input = sc.nextLine().toLowerCase();
- Pattern regex = Pattern.compile("\\w+");
- Matcher matcher = regex.matcher(input);
- Set<String> uniqueWords = new TreeSet<String>();
- while(matcher.find()){
- uniqueWords.add(matcher.group());
- }
- for(String element : uniqueWords){
- System.out.print(element + " ");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment