遍历map中的元素的几种方法
来源:互联网 发布:网上招美工学徒真的吗 编辑:程序博客网 时间:2024/06/05 06:40
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
/**
* 遍历map的几种方法
* @author tpf
*
*/
public class TestMapLookup {
public static void main(String[] args) {
Map <String,Integer> map = new HashMap<String,Integer>();
map.put("aaa", 1);
map.put("ccc", 2);
map.put("bbb", 3);
//方法一for
for(Map.Entry<String,Integer> entry: map.entrySet()){
System.out.println(entry.getKey() + "--->" + entry.getValue());
}
//方法二keySet()
Set<String> set = map.keySet();
Iterator <String> it = set.iterator();
while(it.hasNext()) {
String key = it.next();
int value = map.get(key);
System.out.println(key + "--->" + value);
}
//方法三entrySet()
Set<Map.Entry<String, Integer>> set1 = map.entrySet();
Iterator <Map.Entry<String, Integer>> it1 = set1.iterator();
while(it1.hasNext()) {
Map.Entry<String, Integer> entry = it1.next();
System.out.println(entry.getKey() + "---->" + entry.getValue());
}
}
}
- 遍历map中的元素的几种方法
- 遍历Map的几种方法
- Java 遍历Map的几种方法
- 遍历Map的几种方法
- 遍历Map的几种常用方法
- 遍历Map的几种方法《转载》
- 遍历Map的几种方法
- java Map 遍历的几种方法
- 遍历map的几种方法
- Map的几种遍历方法
- 遍历Map的几种方法
- Map遍历的几种方法
- Map遍历的几种方法
- Map遍历的几种方法
- 遍历map的几种方法
- 几种遍历map的方法
- java 几种遍历map的方法
- 遍历map的几种方法
- Log explorer 对drop/truncate table的数据恢复
- 严重: IOException while loading persisted sessions: java.io.EOFException
- 页面中控件的访问
- JSTL与struts的结合
- Fuzzy can not go on
- 遍历map中的元素的几种方法
- 从程序员到卓越IT职业人-开篇
- 使用ServletContextListener
- Linux学习笔记
- FI--SAP财务成本知识库
- 用JAVA轻松操作properties文件
- bfin-xxx-gcc-4.3.1中auto-host.h的生成
- JAVA面试题解惑系列(二)——到底创建了几个String对象?
- COOKIE用法