fork download
  1. import java.util.Arrays;
  2. import java.util.List;
  3. import java.util.Map;
  4. import java.util.concurrent.ConcurrentHashMap;
  5.  
  6. class Ideone
  7. {
  8. static Map<Integer,Object> map = new ConcurrentHashMap<>();
  9. static int sz;
  10. static
  11. {
  12. List<Integer> list = Arrays.asList(6, 1, 516, 15, 435, 452, 8, 23, 18, 23, 76, 266, 544, 815, 315, 672, 145, 414);
  13. sz = list.size();
  14. for(Integer i : list)
  15. map.put(i, new Object());
  16. }
  17. public static void main (String[] args) throws java.lang.Exception
  18. {
  19. int loop = 1;
  20. for(Integer i : map.keySet())
  21. {
  22. System.out.println("--> "+i+" "+(loop++)+"/"+sz);
  23. update(i);
  24. }
  25. assert(loop == sz);
  26. }
  27. static void update(Integer key)
  28. {
  29. map.remove(key);
  30. map.put(key, new Object());
  31. }
  32. }
Success #stdin #stdout 0.07s 380160KB
stdin
Standard input is empty
stdout
--> 266 1/18
--> 6 2/18
--> 18 3/18
--> 672 4/18
--> 315 5/18
--> 145 6/18
--> 8 7/18
--> 452 8/18
--> 516 9/18
--> 815 10/18
--> 23 11/18
--> 435 12/18
--> 15 13/18
--> 1 14/18
--> 544 15/18
--> 414 16/18
--> 76 17/18