遍历HashMap的几种常用方法
来源:互联网 发布:二维数组赋值运算 编辑:程序博客网 时间:2024/06/18 15:31
1.可以采用keySet()+for循环的方法来遍历,keySet()返回的是一个Key值的集合
Map<String,String> map=new HashMap<String,String>();map.put("key1","value1");map.put("key2","value2");map.put("key3","value3");for(String key:map.keySet()){ system.out.println("key:"+key); system.out.println("value:"+map.get(key));}
2.采用EntrySet()+Iterator进行遍历,EntrySet()返回的是一个Map.Entry的一个集合,它提供getKey(),getValue()方法来获取键值对。
Iterator< Map.Entry<String,String>> it=map.EntrySet().iterator();while(it.hasNext()){ Map.Entry<String,String> entry=it.next(); system.out.println("key:"+entry.getKey()); system.out.println("value:"+entry.getValue());}
3.直接采用EntrySet+for增强进行遍历
for(Map.Entry<String,String> entry:map.entrySet()){ system.out.println("key:"+entry.getKey()); system.out.println("value:"+entry.getValue());}4.取出所有value的值,但是不能取出KEY值
for(String value:map.values()){ <pre name="code" class="html"> system.out.println("value:"+value);}
1 0
- 遍历HashMap的几种常用方法
- 关于hashMap的几种遍历方法
- ArrayList和hashMap的几种遍历方法
- 在Java中,HashMap的几种遍历方法
- 遍历Map的几种常用方法
- HashMap的遍历常用的两种方法
- HashMap遍历的几种方式
- 测试HashMap几种遍历的时间
- HashMap的遍历两种常用的方法,那就是使用keyset及entryset来进行遍历
- HashMap的遍历两种常用的方法,那就是使用keyset及entryset来进行遍历
- HashMap的遍历两种常用的方法,那就是使用keyset及entryset来进行遍历
- HashMap的遍历两种常用的方法,那就是使用keyset及entryset来进行遍历
- HashMap的遍历两种常用的方法,那就是使用keyset及entryset来进行遍历 .
- HashMap的遍历两种常用的方法,那就是使用keyset及entryset来进行遍历
- HashMap的遍历两种常用的方法,那就是使用keyset及entryset来进行遍历
- 遍历HashMap的常用两种方式
- HashMap的遍历方法
- 遍历HashMap的方法
- 奇偶位交换
- 欢迎使用CSDN-markdown编辑器
- Android点击空白区域,隐藏输入法软键盘
- Android下打印调试堆栈方法
- Rsync+Inotify实时同步
- 遍历HashMap的几种常用方法
- [030]八大排序算法详解——希尔排序
- 简单数据结构----链栈的C++实现
- 逻辑回归推导
- javascript变量声明提升(hoisting)
- telnet 使用smtp发送邮件
- android.database.sqlite.SQLiteException: no such table解决方法
- iOS动画效果和实现
- java 引用数据类型