posts - 134,  comments - 22,  trackbacks - 0
最近在网上发现,一个遍历HashMap得好方法。效率比较高。给大家共享 :
     //HashMap遍历
      public static String getMapByEntry(HashMap<String, Integer> hmap) {
            StringBuffer  keywords 
= new StringBuffer();
            String numStr 
="";          
            
//用Set对象打印结果
            Set<Map.Entry<String,Integer>> enterySet = hmap.entrySet();    
            
            
for (Map.Entry<String, Integer> ent : enterySet) {           
                
               keywords.append(ent.getKey() 
+ " " + ent.getValue()+ "\n");
           }            
           
return keywords.toString();
           
     }

如果要根据关键字获得值得话就比较简单了。
     int value = hmap.get(myKeyword)
posted on 2008-07-29 11:13 TRE-China R&D 阅读(1732) 评论(1)  编辑 收藏 引用 所属分类: JAVA
只有注册用户登录后才能发表评论。