Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- import java.util.TreeSet;
- public class _10_ExtractAllUniqueWords {
- public static void main(String[] args) {
- try (Scanner scanner = new Scanner(System.in)) {
- String[] words = scanner.nextLine().split("\\W+");
- TreeSet<String> orderedWords = new TreeSet<>();
- for (int i = 0; i < words.length; i++) {
- orderedWords.add(words[i].toLowerCase());
- }
- // print
- for (String word : orderedWords) {
- System.out.print(word + " ");
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement