HashMap中keySet()以及values()方法的使用
来源:互联网 发布:arena软件下载 编辑:程序博客网 时间:2024/05/18 23:56
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
- textView 解析包含图片的html内容
- jQuery load()方法
- 记录一次远程数据导出导入
- XMLHTTPRequest的方法和属性介绍
- C++指针直接调用类成员函数探讨
- HashMap中keySet()以及values()方法的使用
- 【Cocos2d-x】源码分析之 2d/ui/Widget
- UVa OJ 127 - "Accordian" Patience (“手风琴”纸牌)
- reactor设计模式
- linux读取配置文件(C语言版)
- 黑马程序员_Java基础加强_内省
- Linux判断进程是否存在并启动该进程
- 网页编程.笔记3:符号实体,超链接,表格,上标与下标
- javascript的继承,一个简单的乒乓球游戏