亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Java使用entrySet方法獲取Map集合中的元素

 更新時間:2018年08月20日 10:59:43   作者:Killer-V  
這篇文章主要為大家詳細介紹了Java使用entrySet方法獲取Map集合中的元素,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文為大家分享了使用entrySet方法獲取Map集合中元素的具體代碼,供大家參考,具體內(nèi)容如下

/*---------------------------------
使用entrySet方法取出Map集合中的元素:
....該方法是將Map集合中key與value的關(guān)系存入到了Set集合中,這個關(guān)系的數(shù)據(jù)類型是Map.Entry
....entrySet方法返回值類型的具體寫法為:Set< Map.Entry<KeyType , ValueType> >
----------------------------------*/
package pack04;

import java.util.*;

public class MapDemo {
  public static void main(String[] args) {

    Map<Integer, String> ma = new HashMap<Integer, String>();

    //給集合中存入元素
    ma.put(1, "abc01");  //這里將基本數(shù)據(jù)類型自動裝箱
    ma.put(2, "abc02");
    ma.put(3, "abc03");
    ma.put(4, "abc04");
    
    //將Map集合當中的映射關(guān)系取出,存入到Set集合當中
    Set< Map.Entry<Integer, String> > entryset = ma.entrySet();
    
    //取迭代器
    Iterator< Map.Entry<Integer, String> > it = entryset.iterator();
    
    //獲取Map集合中的元素
    while( it.hasNext() ) {
      Map.Entry<Integer, String> en = it.next();
      Integer maKey = en.getKey();
      String maValue = en.getValue();
      
      System.out.println( maKey + " : " + maValue );
    }
    
  }
}

注:希望與各位讀者相互交流,共同學習進步。

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論