07-双列集合

Map<K,V>

K:键 - (任意类型) - (不可重复) - 可为null

V:值 - (任意类型) - (可重复) - 可为null

HashMap<K,V>

常用方法

方法作用返回值
put(键,值)添加键值对V
get(键)键找值V
remove(键)键删键值对V
replace(键,新值)替换值V
containsKey(key)包含键?boolean
containsValue(value)包含值?boolean
keySet()键集合Set<K>
values()值集合Collection<V>
entrySet()键值对集合Set<Entry>

Entry

保存一组键值对的类型

K getKey() 获取当前键值对对象的键

V getValue() 获取当前键值对对象的值

通过HashMap的entrySet() 获取到的Set<Entry<K,V>>集合 就是HashMap指向的地址

通过Set<Entry<K,V>> 去操作(修改值 删除)每一组Entry 都会影响到HashMap

键遍历集合

Set<String> s = hm.keySet();
Iterator<String> it = s.iterator();
while(it.hasNext()){
    String name = it.next();
    syso(name+":"+hm.get(name));
}

映射关系便利集合

Set<Entry<String, Integer>> s = hm.entrySet();
Iterator<Entry<String, Integer>> it = s.iterator();
while(it.hasNext()) {
    Entry<String, Integer> next = it.next();
    System.out.println(next.getKey()+" "+next.getValue());
}
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值