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. Hashtable<Integer,LinkedList<Integer>> map
  13. = new Hashtable<Integer,LinkedList<Integer>>();
  14.  
  15. int index;
  16. int b;
  17. int x;
  18.  
  19. for (b=0; b<1000000; b++){
  20. x = (int) (Math.random()*1000000000)+1;
  21. index = x % 10000;
  22.  
  23. if(map.get(index) == null){
  24. map.put(index, new LinkedList<Integer>());
  25. map.get(index).add(x);
  26. }else{
  27. map.get(index).add(x);
  28. }
  29. }
  30.  
  31. System.out.println("For map.get(0), size is " + map.get(0).size());
  32. System.out.println("For map.get(1000), size is " + map.get(1000).size());
  33. }
  34. }
Success #stdin #stdout 1.33s 381312KB
stdin
Standard input is empty
stdout
For map.get(0),    size is 96
For map.get(1000), size is 111