fork(1) download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4. import java.io.*;
  5. import java.util.stream.Collectors;
  6.  
  7. class Ideone
  8. {
  9. public static void main(String[] args) {
  10. Map<String, String> map = new HashMap<>();
  11. map.put("Пупкин", "Василий");
  12. map.put("Иванов", "Василий");
  13. map.put("Пушкин", "Александр");
  14.  
  15. Map<String, Integer> counts = new HashMap<>();
  16. map.entrySet().forEach(e -> counts.put(e.getValue(),
  17. counts.getOrDefault(e.getValue(), 0) + 1));
  18. Map<String, String> result = map.entrySet().stream()
  19. .filter(entry -> counts.get(entry.getValue()) == 1)
  20. .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
  21. System.out.println(result);
  22. }
  23. }
Success #stdin #stdout 0.21s 321024KB
stdin
Standard input is empty
stdout
{Пушкин=Александр}