deyanmalinov

03. Odd Occurrences - replaceAll []

Mar 18th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.96 KB | None | 0 0
  1. package DPM;
  2.  
  3. import java.util.*;
  4.  
  5. public class Main {
  6.         public static void main(String[] args) {
  7.             Scanner scan = new Scanner(System.in);
  8.             String [] line = scan.nextLine().split(" ");
  9.             Map <String, Integer> someMap = new LinkedHashMap<>();
  10.             for (String s : line) {
  11.                 String word = s.toLowerCase();
  12.                 if (someMap.containsKey(word)){
  13.                     someMap.put(word, someMap.get(word)+1);
  14.                 }else {
  15.                     someMap.put(word, 1);
  16.                 }
  17.             }
  18.             List<String> res = new ArrayList<>();
  19.             for (Map.Entry<String, Integer> entry : someMap.entrySet()) {
  20.                 if (entry.getValue() % 2 == 1){
  21.                     res.add(entry.getKey());
  22.                 }
  23.             }
  24. //            System.out.println(String.join(", ",res));
  25.             System.out.println(res.toString().replaceAll("\\[|\\]", ""));
  26.         }
  27. }
Add Comment
Please, Sign In to add comment