Map--HashMap
来源:互联网 发布:网络推广的工作职责 编辑:程序博客网 时间:2024/05/22 14:41
HashMap为Map的实现类,无参构造方法调用参数为int(初始容量)和float(加载因子)的构造方法初始化变量.HashMap的内部存储结构其实是数组和链表的结合,数据内容为键值对(key-value)映射,HashMap的key value都可以为null,HashMap的key使用hash值比较,所以key在HashMap为唯一不重复的.key,value封装在Entry(单向链表)对象中存储,所以HashMap存储的数据不是有序的,Entry存储在一个为Entry的数组中.
HashMap的实现不是同步的,这就意味着它不是线程安全的.
1遍历HashMap的键值对
Iterator iter = map.entrySet().iterator();
while(iter.hasNext()) {
Map.Entry entry = (Map.Entry)iter.next();
// 获取key
key = (String)entry.getKey();
// 获取value
integ = (Integer)entry.getValue();
}
2遍历HashMap的键
Iterator iter = map.keySet().iterator();
while (iter.hasNext()) {
// 获取key
key = (String)iter.next();
// 根据key,获取value
integ = (Integer)map.get(key);
}
3遍历HashMap的值
Integer value = null;
Collection c = map.values();
Iterator iter= c.iterator();
while (iter.hasNext()) {
value = (Integer)iter.next();
}
0 0
- map hashmap
- map、hashmap
- Map--HashMap
- Map-HashMap
- map hashMap
- HashMap map= new HashMap();Map map=new HashMap(); 不是Map map=new Map();
- 认识Map之HashMap
- Map与hashMap
- Map ,Hashmap,HashTable,LinkedHashMap
- 遍历HashMap和Map
- Map--HashMap--简单操作
- 【Java】Map之HashMap
- 关于map和hashmap
- map和hashmap
- map-hashMap分组(example)
- Map集合HashMap嵌套
- Map--HashMap实现分析
- Java Map接口HashMap
- 移动web页面支持弹性滚动的3个方案
- FPGA:跨时钟域数据交互
- 网络仿真软件eNSP
- 架构,设计模式的一些整理和杂思
- 第十周第十一周阅读程序-5-e
- Map--HashMap
- 模板
- WebService 之 WSDL文件 讲解
- iOS 正则表达式 NSRegularExpression
- 【JDK】环境变量配置
- Shell脚本定义变量和环境变量的引用
- xshow-2. 使用HTML 5 Boilerplate构建前端
- arm移植php
- 解决ubuntu/linux mint没有声音的问题