hashmap的遍历
import java.util.HashMap;
import java.util.Iterator; public class hash { /**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
HashMap<String, String>hm=new HashMap<String, String>();
hm.put("100","001");
hm.put("200","002");
hm.put("300","003");
hm.put("400","004");
hm.put("500","005");
hm.put("600","006");
hm.put("700","007");
hm.put("800","008");
hm.put("900","009");
System.out.println(hm.get("100"));
System.out.println(hm.size());
}
}
方式1
Iterator iterator = hm.keySet().iterator();
while(iterator.hasNext()) {
System.out.println(hm.get(iterator.next()));
}
方式2
Set set = hm.entrySet() ;
java.util.Iterator it = hm.entrySet().iterator();
while(it.hasNext()){
java.util.Map.Entry entry = (java.util.Map.Entry)it.next();
// entry.getKey() 返回与此项对应的键
// entry.getValue() 返回与此项对应的值
System.out.println(entry.getValue());
}
hashmap的遍历的更多相关文章
- HashMap循环遍历方式及其性能对比(zhuan)
http://www.trinea.cn/android/hashmap-loop-performance/ ********************************************* ...
- HashMap循环遍历方式及其性能对比
主要介绍HashMap的四种循环遍历方式,各种方式的性能测试对比,根据HashMap的源码实现分析性能结果,总结结论. 1. Map的四种遍历方式 下面只是简单介绍各种遍历示例(以HashMap为 ...
- HashMap的遍历和排序
1.HashMap的遍历 package com.sheepmu; import java.util.HashMap; import java.util.Iterator; import java.u ...
- HashMap集合-遍历方法
# HashMap集合-遍历方法 先定义好集合: public static void main(String[] args) { Map<String,String> onemap=ne ...
- ArrayList、LinkedList、HashMap的遍历及遍历过程中增、删元素
ArrayList.LinkedList.HashMap是Java中常用到的几种集合类型,遍历它们是时常遇到的情况.当然还有一些变态的时候,那就是在遍历的过程中动态增加或者删除其中的元素. 下面的例子 ...
- 无限层级且乱序的树形结构数据的整理,利用HashMap降低遍历次数
我们在展示一个机构树的时候,经常会遇到这种一个问题,查询数据的时候,是从下往上查的,但展示数据的时候,又要从下往上展示. 这时候就要把查询到的数据进行整理从而得到我们想要的结构. 举个样例. ID P ...
- java之HashMap的遍历Iterator
package com.ql_2;/* * 功能:HashMap 的使用 */import java.util.*; public class Test_2 { public static void ...
- HashMap 的遍历key与value的方法
HashMap最经常使用的使用方法是依据key增删改查value,有时候会须要知道一个HashMap有多少个keys以及这些keys都是什么,能够用以下的代码实现. 方法1: Map map = ne ...
- hashmap的遍历方法
How to iterate over the entries of a Map? What is the order of iteration - if you are just using Map ...
随机推荐
- Java 8 VM GC Tuning Guide Charter2
第二章 Ergonomics Ergonomics is the process by which the Java Virtual Machine (JVM) and garbage collect ...
- Eclipse启动的时候窗口一闪就关的解决办法(转)
有时候会碰到如题这种问题,从网上查知解决办法,非常管用 为eclipse.exe创建一个快捷方式,然后快捷方式上右键-属性,在目标栏填入 E:\eclipse\eclipse.exe -vm &quo ...
- highCharts 电流表、电压表
var highChartsSettingV = { chart: { margin: [5, 2, 5, 8], type: 'gauge', plotBorderWidth: 1, plotBac ...
- 管道Pipe
管道Pipe java.nio.channels包中含有一个名为Pipe(管道)的类.广义上讲,管道就是一个用来在两个实体之间单向传输数据的导管.管道的概念对于Unix(和类Unix)操作系统的用户来 ...
- hadoop 技巧
通过--config指定不同的集群 bin/hadoop --config ./conf_time/ dfs -ls /user/rd/*/for_*/ip_table/output/ rd下是都读写 ...
- 设置DIV隐藏与显示,表格滑动条
问题描述: 现在希望使用JS设置DIV块的显示与隐藏,当某一个事件触发是,自动显示DIV块,显示表格数据,但是要求表格显示滑动条 问题解决: (1)DIV块的隐藏与显示 如上所示, ...
- 【BZOJ】【3295】【CQOI2011】动态逆序对
树套树 Orz zyf神犇 时光倒流……逆序处理,将删点改为加点,动态维护序列. 由于是动态,要加点,所以用树状数组:同时又需要求序列中求比当前元素大/小的元素个数,所以要用平衡树. 所以方法就是在树 ...
- [bzoj 2159]Crash的文明世界
今天看到一个鬼题 心情好的时候写 [题意]求树上所有点对距离的k次方和,所有边权为1 大爷方的题解:http://tonyfang.is-programmer.com/posts/204972.htm ...
- 表中相同数据的sql语句
1.查找表中多余的重复记录,重复记录是根据单个字段(peopleId)来判断select * from peoplewhere peopleId in (select peopleId from ...
- maven3常用命令、java项目搭建、web项目搭建详细图解
http://blog.csdn.net/edward0830ly/article/details/8748986 ------------------------------maven3常用命令-- ...