Map用法
来源:互联网 发布:内涵吧源码 编辑:程序博客网 时间:2024/06/18 08:36
Map<String, String> map = new HashMap<String, String>();map.put("1", "value1");map.put("2", "value2");map.put("3", "value3"); //第一种:普遍使用,二次取值System.out.println("通过Map.keySet遍历key和value:");for (String key : map.keySet()) { System.out.println("key= "+ key + " and value= " + map.get(key));}//第二种System.out.println("通过Map.entrySet使用iterator遍历key和value:");Iterator<Map.Entry<String, String>> it = map.entrySet().iterator();while (it.hasNext()) { Map.Entry<String, String> entry = it.next(); System.out.println("key= " + entry.getKey() + " and value= " + entry.getValue());} //第三种:推荐,尤其是容量大时System.out.println("通过Map.entrySet遍历key和value");for (Map.Entry<String, String> entry : map.entrySet()) { System.out.println("key= " + entry.getKey() + " and value= " + entry.getValue());}//第四种System.out.println("通过Map.values()遍历所有的value,但不能遍历key");for (String v : map.values()) {
阅读全文
0 0
- map用法
- map用法
- map用法
- Map用法
- map用法
- Map用法
- map用法
- map用法
- MAP用法
- map用法
- map用法
- map用法
- map 用法
- MAP用法
- map用法
- map用法
- map用法
- map用法
- C语言的作用
- HashMap HashTable LinkedHashMap TreeMap
- 两道多线程打印题目
- Apache Maven的插件概述
- bzoj 3574: [Hnoi2014]抄卡组 (字符串Hash)
- Map用法
- ECLIPSE 快捷键
- 组合模式Composite(结构型)
- 15、jQuery插件之slider幻灯片插件(可悬停控制)
- js实现跨域
- MarkdownView:Markdown 文档预览视图组件
- Android NDK入门
- 移动端图片上传的实践
- 谈谈数据结构