HashMap
来源:互联网 发布:python dictionary 编辑:程序博客网 时间:2024/05/16 10:19
HashMap的toy code
import java.util.*;/** * Description:find the number which appear the most frequently in an array * @author Biang Hoo * Aug 19 2013 */public class HashSetTest {public static void main(String []args){int array[]={1,2,3,4,5,6,7,3,2,3,1,6,4,1,3,};HashMap<Integer,Integer> hs = new HashMap<Integer,Integer>();for(Integer m:array){//遍历数组,将数和它个数作为键和值存入HashMapint i=1;if(hs.get(m)!= null){ i = (hs.get(m))+1;}hs.put(m,i);//System.out.println(hs.get(m));}Iterator itor= hs.keySet().iterator();int MAX =-1;Object Max_Key=null;while(itor.hasNext()){//找到出现次数最多的数Object key = itor.next();if(hs.get(key)>MAX){MAX = hs.get(key);Max_Key =key;}}System.out.println(Max_Key+" "+hs.get(Max_Key));}}
- HashMap
- HashMap
- HashMap
- HashMap
- HashMap
- HashMap
- HashMap
- HashMap
- HashMap
- HashMap
- HashMap
- hashmap
- HashMap
- HashMap
- HashMap
- hashmap
- HashMap
- Hashmap
- 百度星火原创计划?别抱幻想了
- 实战memcpy------libc
- 1354和为S的连续正数
- 开源轻量级jquery validation 验证插件
- AsyncTask,Handler,Looper
- HashMap
- UVA 1361 Cactus (改)
- hdu4568 Hunter
- HDU_2031 进制转换
- CBLAS的安装与使用
- Unity的一些笔试题,大侠们帮忙改改答案哦!
- hdu1800 Flying to the Mars (字典树)
- 注解方式配置spring
- wordpress添加顶级菜单