fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6. import java.util.HashMap;
  7. import java.util.Map;
  8. import java.util.concurrent.atomic.AtomicInteger;
  9.  
  10. /* Name of the class has to be "Main" only if the class is public. */
  11. class Ideone
  12. {
  13. public static void main (String[] args) throws java.lang.Exception
  14. {
  15. Map<String, Map<String, Integer>> before = new HashMap<>();
  16. Map<String, Integer> map11 = new HashMap<>();
  17. map11.put("foo", 1);
  18. before.put("foo", map11);
  19. Map<String, Integer> map12 = new HashMap<>();
  20. map12.put("bar", 2);
  21. before.put("bar", map12);
  22. Map<Integer, Map<String, Integer>> after = new HashMap<>();
  23.  
  24. System.out.println(before);
  25.  
  26. before.values().forEach(value -> after.put(after.size(), value));
  27.  
  28. System.out.println(after);
  29. }
  30. }
Success #stdin #stdout 0.2s 33244KB
stdin
Standard input is empty
stdout
{bar={bar=2}, foo={foo=1}}
{0={bar=2}, 1={foo=1}}