HashMap中keySet()以及values()方法的使用
来源:互联网 发布:数据汇聚层的作用 编辑:程序博客网 时间:2024/05/19 01:07
Map是一个映射,里面的数据是无序的,这一点HashSet是一样的,另外Map最独特的地方是,它是成对出现的。由于Map是一个接口,所以我们来研究一下实现它的类HashMap;
HashMap hashMap = new HashMap();
hashMap.put("a","zhang");
hashMap.put("a","zhang");
hashMap.put("a","zhang");
System.out.println(hashMap);
这样便会得到里面的所有的信息;
hashMap.get("a");
取出单个信息zhang;
HashMap中键不能重复,但是只可以任意重复;
hashMap.keySet() return Set
这是因为键是不重复的,而Set的键也是不重复的
hashMap.values() return Conllection
这是因为hasnmap中值是可以重复的就像Conllection中的也可以重复
下面讲一个最常用的遍历HashMap的方法:
public class HashMapTest
{
public static void main(String[] args)
{
HashMap hashMap = new HashMap();
hashMap.put("a", "zhang");
hashMap.put("b", "zhang");
hashMap.put("c", "zhng");
Set set = hashMap.keySet();
for(Iterator iterator = set.iterator();iterator.hasNext();)
{
String s1 = (String)iterator.next();
String s2 = (String)hashMap.get(s1);
System.out.println(s1+":"+s2);
}
}
}
这次讲的知识点有点少啊,我再加紧学习,多积累积累,希望那天能有更深层次的交流,这样才有资格跟那些大牛切磋啊,期待。。。。。。
- HashMap中keySet()以及values()方法的使用
- HashMap中keySet()以及values()方法的使用
- jdk:HashMap的keySet(),values(),entrySet()
- Map的keySet(),entrySet(),values()方法
- Java中遍历Map的三种方法:keySet、entrySet 、values()
- Hashmap 中的Keyset()方法
- java中Map中的keySet,values,entrySet的区别
- HashMap的遍历两种常用的方法,那就是使用keyset及entryset来进行遍历
- HashMap的遍历两种常用的方法,那就是使用keyset及entryset来进行遍历
- HashMap的遍历两种常用的方法,那就是使用keyset及entryset来进行遍历
- HashMap的遍历两种常用的方法,那就是使用keyset及entryset来进行遍历
- HashMap的遍历两种常用的方法,那就是使用keyset及entryset来进行遍历 .
- HashMap的遍历两种常用的方法,那就是使用keyset及entryset来进行遍历
- HashMap的遍历两种常用的方法,那就是使用keyset及entryset来进行遍历
- 遍历hashmap的键值一,通过 keySet()方法
- HashMap 中的keySet()和entrySet()方法的比较
- HashMap的entrySet与keySet
- HashMap的entrySet与keySet
- 初试——Hanoi塔问题
- mmap设备方法笔记
- Linq To Object 查询语句示例
- 记录:s:property标签的其他属性——default和escape
- 智慧背囊小故事
- HashMap中keySet()以及values()方法的使用
- 当前java开发中的几种认识误区
- inline关键字
- 工厂模式
- 【Android代码片段之七】判断sdCard是否已安装的两种方法
- 记录:s:iterator的一些使用(status,begin和end)
- Keepalived 双机热备
- 详细解析java 中抽象类与接口的区别
- 比较ASCII字符(用户权限)