久久久精品一区ed2k-女人被男人叉到高潮的视频-中文字幕乱码一区久久麻豆樱花-俄罗斯熟妇真实视频

利用java怎么將Map轉化為二維數組-創(chuàng)新互聯

利用java 怎么將Map轉化為二維數組?相信很多沒有經驗的人對此束手無策,為此本文總結了問題出現的原因和解決方法,通過這篇文章希望你能解決這個問題。

創(chuàng)新互聯公司10多年企業(yè)網站制作服務;為您提供網站建設,網站制作,網頁設計及高端網站定制服務,企業(yè)網站制作及推廣,對被動防護網等多個行業(yè)擁有多年的網站營銷經驗的網站建設公司。

實例代碼:

import java.util.HashMap; 
import java.util.Iterator; 
import java.util.Map; 
 
public class Test { 
  public static void main(String[] args) { 
    int a = 0, b = 0, c = 0; 
    // 第一種:通過Map.keySet()遍歷Map及將Map轉化為二維數組 
    Map<String, String> map1 = new HashMap<String, String>(); 
    map1.put("012013012013", "張三"); 
    map1.put("012013012014", "張四"); 
    String[][] group1 = new String[map1.size()][2]; 
    System.out.println("第一種:通過Map.keySet()遍歷map1的key和value"); 
    for (String key : map1.keySet()) {  
      System.out.println("key = " + key + " and value = " + map1.get(key));  
      group1[a][0] = key; 
      group1[a][1] = map1.get(key); 
      a++; 
    }  
    System.out.println("map1.size()為:" + map1.size() + ",a為:" + a + ",group1數組的長度為:" + group1.length); 
    System.out.println("----------------------------------------------------"); 
    for(int n = 0; n < group1.length; n++) { 
      System.out.println("key = " + group1[n][0] + " and value = " + group1[n][1]);  
    } 
     
    // 第二種:通過Map.entrySet()使用iterator()遍歷Map及將Map轉化為二維數組 
    Map<String, String> map2 = new HashMap<String, String>(); 
    map2.put("112013012013", "李三"); 
    map2.put("112013012014", "李四"); 
    System.out.println("\n" + "第二種:通過Map.entrySet()使用iterator()遍歷map2的key和value"); 
    Iterator<Map.Entry<String, String>> iterator = map2.entrySet().iterator();  
    String[][] group2 = new String[map2.size()][2]; 
    while (iterator.hasNext()) {  
      Map.Entry<String, String> entry = iterator.next();         
      System.out.println("key = " + entry.getKey() + " and value = " + entry.getValue()); 
      group2[b][0] = entry.getKey(); 
      group2[b][1] = entry.getValue(); 
      b++; 
    }  
    System.out.println("map2.size()為:" + map2.size() + ",b為:" + b + ",group2數組的長度為:" + group2.length); 
    System.out.println("----------------------------------------------------"); 
    for(int n = 0; n < group2.length; n++) { 
      System.out.println("key = " + group2[n][0] + " and value = " + group2[n][1]);  
    } 
     
    // 第三種:通過Map.entrySet()遍歷遍歷Map及將Map轉化為二維數組 
    Map<String, String> map = new HashMap<String, String>(); 
    map.putAll(map1); 
    map.putAll(map2);   
    String[][] group3 = new String[map.size()][2]; 
    System.out.println("\n" + "第三種:通過Map.entrySet()遍歷map的key和value ");    
    for (Map.Entry<String, String> entry : map.entrySet()) {  
      System.out.println("key = " + entry.getKey() + " and value = " + entry.getValue());  
      group3[c][0] = entry.getKey(); 
      group3[c][1] = entry.getValue(); 
      c++; 
    } 
    System.out.println("map.size()為:" + map.size() + ",c為:" + c + ",group3數組的長度為:" + group3.length); 
    System.out.println("----------------------------------------------------"); 
    for(int n = 0; n < group3.length; n++) { 
      System.out.println("key = " + group3[n][0] + " and value = " + group3[n][1]);  
    } 
     
  } 
} 

當前名稱:利用java怎么將Map轉化為二維數組-創(chuàng)新互聯
文章位置:http://www.sd-ha.com/article46/epoeg.html

成都網站建設公司_創(chuàng)新互聯,為您提供網站內鏈、網站導航App開發(fā)、App設計品牌網站建設、電子商務

廣告

聲明:本網站發(fā)布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯

網站托管運營