A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 403806022 中级黑马   /  2016-4-7 21:08  /  630 人查看  /  8 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

Map map=new HashMap();                
map.put(“jessica”,100);                
map.put(“tom”,200);                
map.put(“den”,300);                
Set <Entry<Integer,String >> set = map.entrySet() ;                
for ( Entry  per : set) {                        
System.out.println(per.getKey() + ":" + per.getValue());                
}  
请问这个程序哪里有问题呢?为什么编译有问题呢?

8 个回复

倒序浏览
应该是Set<Map.Entry<String,Integer>> set=map.entrySet();     
回复 使用道具 举报
泛型没有写
回复 使用道具 举报
Map map=new HashMap();
回复 使用道具 举报
注意泛型问题,在集合中要写出来,不能你加的元素是<String,Integer>,程序中写的是<Integer,String>
回复 使用道具 举报
先是创建集合的时候没有定义泛型,
Map<String,Integer > map=new HashMap<String,Integer>();  
                map.put("jessica",100);                 
                map.put("tom",200);                 
                map.put("den",300);   

        Set<Entry<String, Integer>> entrySet = map.entrySet() ;                 
                for ( Entry<String, Integer>  per : entrySet) {                        
                System.out.println(per.getKey() + ":" + per.getValue());                 
                }
正确答案
回复 使用道具 举报
没错啊,能编译运行 是不是你的符号不对啊?
回复 使用道具 举报
这个真不知道  
回复 使用道具 举报
这个真不知道0
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马