码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2016-11-19 16:13:39      阅读:191      评论:0      收藏:0      [点我收藏+]

标签:分享   nbsp   out   shm   src   学习笔记   and   http   rand   

 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的应用

标签:分享   nbsp   out   shm   src   学习笔记   and   http   rand   

原文地址:http://www.cnblogs.com/yansum/p/6080487.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!