<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    從制造到創造
    軟件工程師成長之路
    posts - 292,  comments - 96,  trackbacks - 0
      1 /**
      2  * MapTest.java
      3  *
      4  * Provider: CoderDream's Studio
      5  *
      6  * History
      7  *    Date(DD/MM/YYYY)    Author          Description
      8  * ----------------------
      9  *    Oct 31, 2007        CoderDream        Created
     10  */
     11 package com.coderdream;
     12 
     13 import java.util.HashMap;
     14 import java.util.Iterator;
     15 import java.util.Map;
     16 import java.util.TreeMap;
     17 
     18 /**
     19  * @author CoderDream
     20  */
     21 public class MapTest {
     22 
     23     /**
     24      * <pre>
     25      *         使用HashMap使用1:
     26      *             用迭代器得到map.entrySet(),
     27      *             然后通過迭代得到Map.Entry對象,最后打印。
     28      *             打印結果未排序
     29      * </pre>
     30      * 
     31      */
     32     public void f1() {
     33         Map map = new HashMap();
     34         map.put("1""Level 1");
     35         map.put("2""Level 2");
     36         map.put("3""Level 3");
     37         map.put("4""Level 4");
     38         map.put("F""Level F");
     39         map.put("Q""Level Q");
     40         Iterator it = map.entrySet().iterator();
     41         while (it.hasNext()) {
     42             Map.Entry e = (Map.Entry) it.next();
     43             System.out.println("Key: " + e.getKey() + "; Value: "
     44                     + e.getValue());
     45         }
     46     }
     47 
     48     /**
     49      * <pre>
     50      * 使用泛型模式說明Map中存儲的對象類型
     51      * </pre>
     52      */
     53     public void f2() {
     54         Map<String, String> map = new HashMap<String, String>();
     55         map.put("1""Mon.");
     56         map.put("1""Monday");
     57         map.put("one""Monday");
     58         Iterator<Map.Entry<String, String>> it = map.entrySet().iterator();
     59 
     60         while (it.hasNext()) {
     61             Map.Entry entry = it.next();
     62             System.out.println(entry.getKey() + ":" + entry.getValue());
     63         }
     64     }
     65 
     66     /**
     67      * <pre>
     68      * 通過集合Set來得到HashMap中的對象
     69      * </pre>
     70      * 
     71      */
     72     public void f3() {
     73         Map map = new HashMap();
     74         map.put("1""Mon.");
     75         map.put("1""Monday");
     76         map.put("one""Monday");
     77         Iterator it = map.keySet().iterator();
     78         String tmpKey = null;
     79         while (it.hasNext()) {
     80             tmpKey = (String) it.next();
     81             System.out.println("Key: " + tmpKey 
     82                     + "; Value: " + map.get(tmpKey));
     83         }
     84     }
     85 
     86     /**
     87      * <pre>
     88      *     使用TreeMap代替HashMap,取得結果是排序后的結果
     89      * </pre>
     90      */
     91     public void f4() {
     92         Map map = new TreeMap();
     93         map.put("1""Level 1");
     94         map.put("2""Level 2");
     95         map.put("3""Level 3");
     96         map.put("4""Level 4");
     97         map.put("F""Level F");
     98         map.put("Q""Level Q");
     99         Iterator it = map.entrySet().iterator();
    100         while (it.hasNext()) {
    101             Map.Entry e = (Map.Entry) it.next();
    102             System.out.println("Key: " + e.getKey() 
    103                     + "; Value: " + e.getValue());
    104         }
    105     }
    106 
    107     /**
    108      * @param args
    109      */
    110     public static void main(String[] args) {
    111 
    112         MapTest mt = new MapTest();
    113         System.out.println("----------f1()----------");
    114         mt.f1();
    115         System.out.println("----------f2()----------");
    116         mt.f2();
    117         System.out.println("----------f3()----------");
    118         mt.f3();
    119         System.out.println("----------f4()----------");
    120         mt.f4();
    121     }
    122 }


    輸出結果:

    ----------f1()----------
    Key: 
    3; Value: Level 3
    Key: 
    2; Value: Level 2
    Key: F; Value: Level F
    Key: 
    1; Value: Level 1
    Key: Q; Value: Level Q
    Key: 
    4; Value: Level 4
    ----------f2()----------
    1:Monday
    one:Monday
    ----------f3()----------
    Key: 
    1; Value: Monday
    Key: one; Value: Monday
    ----------f4()----------
    Key: 
    1; Value: Level 1
    Key: 
    2; Value: Level 2
    Key: 
    3; Value: Level 3
    Key: 
    4; Value: Level 4
    Key: F; Value: Level F
    Key: Q; Value: Level Q
    posted on 2007-10-31 15:05 CoderDream 閱讀(5132) 評論(0)  編輯  收藏 所屬分類: 經驗點滴

    <2007年10月>
    30123456
    78910111213
    14151617181920
    21222324252627
    28293031123
    45678910

    常用鏈接

    留言簿(9)

    我參與的團隊

    隨筆分類(245)

    隨筆檔案(239)

    文章分類(3)

    文章檔案(3)

    收藏夾(576)

    友情鏈接

    搜索

    •  

    積分與排名

    • 積分 - 459733
    • 排名 - 114

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 亚洲国产综合精品中文第一区| 国拍在线精品视频免费观看| 一级a性色生活片久久无少妇一级婬片免费放 | 亚洲国产精品成人网址天堂| 免费看的成人yellow视频| 成人无遮挡裸免费视频在线观看| 午夜国产精品免费观看| 97视频免费在线| 成年在线观看网站免费| 啦啦啦中文在线观看电视剧免费版| 中国在线观看免费高清完整版| 日韩欧毛片免费视频| 国产99视频精品免费观看7| 一个人免费高清在线观看| 女性无套免费网站在线看| 在线精品免费视频无码的| 日韩免费无砖专区2020狼| 免费A级毛片无码A| 久久久久国产亚洲AV麻豆| 国产精品亚洲精品日韩已满| 亚洲AV无码精品无码麻豆| 99久久亚洲精品无码毛片| 亚洲国产成人精品青青草原| 亚洲看片无码在线视频| 豆国产96在线|亚洲| 一本一道dvd在线观看免费视频| 91免费在线视频| 特级精品毛片免费观看| 国产日本一线在线观看免费| 大香人蕉免费视频75| 亚洲国产成人五月综合网| 亚洲AV无码久久精品色欲| 亚洲成人黄色网址| 337P日本欧洲亚洲大胆艺术图 | 亚洲美女大bbbbbbbbb| 国产成人精品日本亚洲11| 美女18毛片免费视频| 久久精品国产免费一区| 免费看国产成年无码AV片| 亚洲国产午夜福利在线播放| 无码久久精品国产亚洲Av影片|