fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. // your code goes here
  13. HashMap<String,String> map = new HashMap<String,String>();
  14. map.put("key1", "1");
  15. map.put("key2", "2");
  16. map.put("key3", "1");
  17. map.put("key4", "4");
  18. final Set<String> keys = map.keySet();
  19. for (final Iterator<String> it = keys.iterator(); it.hasNext(); ) {
  20. final String key = it.next();
  21. if (map.get(key) != null && map.get(key).equals("1")) {
  22. System.out.println(key);
  23. it.remove();
  24. }
  25. }
  26. System.out.println(map.size());
  27. }
  28. }
Success #stdin #stdout 0.06s 380160KB
stdin
Standard input is empty
stdout
key3
key1
2