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.lang.reflect.Field;
  7.  
  8. /* Name of the class has to be "Main" only if the class is public. */
  9. class Ideone
  10. {
  11. public static void main (String[] args) throws java.lang.Exception
  12. {
  13. HashMap<Integer, Integer> map = new HashMap<Integer, Integer>(20, 500);
  14. Field tableField = HashMap.class.getDeclaredField("table");
  15. tableField.setAccessible(true);
  16. int prevLength = ((Object[]) tableField.get(map)).length;
  17. System.out.println(map.size() + " " + prevLength);
  18. for (int i = 0; i < 130000; i++) {
  19. map.put(i, i);
  20. Object[] table = (Object[]) tableField.get(map);
  21. if (table.length != prevLength) {
  22. System.out.println(map.size() + " " + table.length);
  23. prevLength = table.length;
  24. }
  25. }
  26. }
  27. }
Success #stdin #stdout 2.63s 380352KB
stdin
Standard input is empty
stdout
0 32
16001 64
32001 128
64001 256
128001 512