java中HashMap有什么用,举例说明?

3.8 HashMap的用法

马克-to-win:HashMap和HashSet很像,只不过它里面存的是一个一个的键值对。

例:3.8.1

import java.util.*;
public class TestMark_to_win {
    public static void main(String[] args) {
        Map<String, String> m = new HashMap<String, String>();
        m.put("zs", "333-6666");
        m.put("ls", "111-2222");
        m.put("wwMark", "444-7777");
        Iterator iter = m.entrySet().iterator();
        while (iter.hasNext()) {
            Map.Entry e = (Map.Entry) iter.next();
            System.out.println(e.getKey() + " " + e.getValue());
        }
    }
}
 

 

更多内容请见原文,原文转载自:https://blog.csdn.net/qq_44639795/article/details/103087424

posted @ 2021-07-14 09:20  小龙虾1  阅读(120)  评论(0)    收藏  举报