Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.Scanner;
- public class ExtractAllUniqueWords {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- String input = sc.nextLine().toLowerCase();
- String[] words = input.split("\\W+");
- ArrayList<String> finalWords = new ArrayList<>();
- for (int i = 0; i < words.length; i++) {
- if(!finalWords.contains(words[i])) {
- finalWords.add(words[i]);
- }
- }
- finalWords.sort(null);
- for (String str : finalWords) {
- System.out.print(str + " ");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement