首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 其他教程 > 其他相关 >

依据数值取键

2013-04-05 
根据数值取键import java.util.HashMapimport java.util.Iteratorimport java.util.Mapimport java.uti

根据数值取键
import java.util.HashMap;import java.util.Iterator;import java.util.Map;import java.util.Set;public class TestMap {public static void main(String[] args) {// TODO Auto-generated method stubMap m1 = new HashMap();Map m2 = new HashMap();m1.put("a", new Integer(1));m1.put("b", new Integer(2));m1.put("b", "3");m2.put("f", new Integer(1));m2.put("x", new Integer(2));m2.put("y", new Integer(2));m2.put("z", new Integer(2));m2.put("w", new String("abcd"));//System.out.println(m2.containsKey("q"));//System.out.println(m2.containsValue(new Integer(2)));if(m2.containsValue(new Integer(2))){Set<Map.Entry<Object,Object>> s = m2.entrySet();Iterator i = s.iterator();while(i.hasNext()){Map.Entry<Object,Object> m = (Map.Entry<Object,Object>)i.next();if(m.getValue().equals(new Integer(2))){System.out.print(m.getKey() + " ");}}//System.out.println(m2.entrySet());}else{System.out.println("查无此项");}}}

?

热点排行