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