map通過value獲取對應key


遍歷Map並通過value獲取相應key值

 

  1. Map<String,String> map = new HashMap<String,String>();  
  2. map.put("1", "a");  
  3. map.put("2", "b");  
  4. map.put("3", "c");  
  5. map.put("4", "d");  
  6. map.put("5", "e");  
  7. Set set=map.entrySet();  
  8. Iterator it=set.iterator();  
  9. while(it.hasNext()) {  
  10.    Map.Entry entry=(Map.Entry)it.next();  
  11.    if(entry.getValue().equals("a")) {  
  12.      System.out.println(entry.getKey());  
  13.    }  
  14.    if(entry.getValue().equals("b")){  
  15.         System.out.println(entry.getKey());  
  16.    }  
  17.    if(entry.getValue().equals("c")){  
  18.         System.out.println(entry.getKey());  
  19.    }  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM