Random rand = new Random(47);
	   Map<Integer,Integer> m = new HashMap<Integer,Integer>();
	   for(int i=0;i<10000;i++){
		   int r= rand.nextInt(20);
		   Integer freq =m.get(r);
		   m.put(r,freq==null?1:freq+1);
	   }
	   System.out.println(m);
/*
输出
{0=481, 1=502, 2=489, 3=508, 4=481, 5=503, 6=519, 7=471, 8=468, 9=549, 10=513, 11=531, 12=521, 13=506, 14=477, 15=497, 16=533, 17=509, 18=478, 19=464}

*/

  Thinking in java学习笔记之map的应用

 

相关文章:

  • 2021-11-24
  • 2022-02-05
  • 2021-11-24
  • 2022-01-29
  • 2021-11-01
  • 2022-02-07
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-04-30
  • 2022-12-23
  • 2021-10-05
相关资源
相似解决方案