Guest User

Untitled

a guest
Jan 17th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. public static void main(String[] args) {
  2. ConcurrentHashMap<String, String> c = new ConcurrentHashMap<String, String>();
  3. c.put("1", "a");
  4. c.put("2", "b");
  5. c.put("3", "c");
  6. c.put("4", "d");
  7.  
  8. // The following code won't fail
  9. for (Map.Entry<String, String> entry : c.entrySet()) {
  10. c.put("5", "e");
  11. System.out.println("Key = " + entry.getKey() + ", Value = " + entry.getValue());
  12. c.put("6", "f");
  13. }
  14.  
  15. // another flavour of the above code which would fail neither
  16.  
  17. for(String str:c.keySet()) {
  18. c.put("5", "e");
  19. System.out.println(c.get(str));
  20. c.put("6", "f");
  21. }
  22. }
Add Comment
Please, Sign In to add comment