Map 遍历的几种方法
复习map的过程中想到的,做个简单的记录
public class HashMapTest { public static void main(String args[]) {
Map<Integer, Integer> hm = new HashMap<Integer, Integer>();
hm.put(1, 8);
hm.put(2, 7);
hm.put(3, 6);
hm.put(4, 5);
System.out.println(hm);
System.out.println("第一种:foreach循环");
for (Integer i : hm.keySet()) {
Integer a = hm.get(i);
System.out.println(a);
} System.out.println("第二种:迭代器");
Iterator<Map.Entry<Integer, Integer>> it = hm.entrySet().iterator();
while (it.hasNext()) {
System.out.println(it.next().getValue());
} System.out.println("第三种:");
for (Map.Entry<Integer, Integer> entry : hm.entrySet()) {
System.out.println(entry.getKey() + "--" + entry.getValue());
} } }
Map 遍历的几种方法的更多相关文章
- map遍历的四种方法
public static void main(String[] args) { Map<String, String> map = new HashMap<String, Stri ...
- Map遍历的几种方法
查看Map自带API map遍历方法: public static void main(String[] args) { Map<Integer,String> map = new Has ...
- (转载)Java中如何遍历Map对象的4种方法
在Java中如何遍历Map对象 How to Iterate Over a Map in Java 在java中遍历Map有不少的方法.我们看一下最常用的方法及其优缺点. 既然java中的所有map都 ...
- map遍历的四种方式
原文 http://blog.csdn.net/dayanxuqun/article/details/26348277 以下是map遍历的四种方式: // 一.推荐只用value的时候用,都懂的... ...
- JavaScript遍历对象4种方法和遍历数组的3种方式 代码
//遍历对象 4种方法 //Object.keys(obj).forEach() console.log("keys...遍历</br>") var obj1 = { ...
- Map集合遍历的2种方法
Map是一个集合的接口,是key-value相映射的集合接口,集合遍历的话,需要通过Iterator迭代器来进行. Iterator是什么东西: java.util包下的一个接口: 对 collect ...
- 遍历Map key-value的两种方法
以前遍历Map key-value比较习惯的方式是先获取Map中的所有key值,然后根据key,依次从Map中去数据,基本方式如下: Map<String,String> testData ...
- map集合遍历的五种方法
package com.jackey.topic; import java.util.ArrayList;import java.util.HashMap;import java.util.Itera ...
- Map<String, String> 遍历的四种方法
Map<String, String> map = new HashMap<String, String>(); map.put("key1", " ...
随机推荐
- [Javascript Crocks] Create a Maybe with a `safe` Utility Function
In this lesson, we’ll create a safe function that gives us a flexible way to create Maybes based on ...
- 通过UrlRewriter配置MVC4伪静态
有些项目须要设置静态.这样能够被站点收录了,提高站点的排名.内容. 假设地址后面有www.a.com/xx.html?id=1是不行,还是不能达到一些需求.怎么才干实现www.a.com/1/xx.h ...
- 【小超_Android】GitHub源码项目整理,希望对大家有帮助
收集的经常使用Github上比較优秀的项目,希望对大家日常开发有所帮助: AndroidSlidingMenu https://github.com/jfeinstein10/SlidingMen ...
- python实现高速排序算法(两种不同实现方式)
# -*- coding: utf-8 -*- """ Created on Fri May 16 17:24:05 2014 @author: lifeix " ...
- 【SCOI 2005】 骑士精神
[题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=1085 [算法] IDA* [代码] #include<bits/stdc++. ...
- POJ 3258 (NOIP2015 D2T1跳石头)
河中跳房子 总时间限制: 1000ms 内存限制: 65536kB 描述 每年奶牛们都要举办各种特殊版本的跳房子比赛,包括在河里从一个岩石跳到另一个岩石.这项激动人心的活动在一条长长的笔直河道中进行, ...
- A - Boy or Girl(set)
Problem description Those days, many boys use beautiful girls' photos as avatars in forums. So it is ...
- ViewData与ViewBag的使用区别
在Asp.net MVC 3 web应用程序中,我们会用到ViewData与ViewBag,对比一下: ViewData ViewBag 它是Key/Value字典集合 它是dynamic类型对像 从 ...
- JavaScript命名空间的理解与实现
命名空间有效防止函数名/类名和其他人的冲突,在使用多个第三方框架或类库的时候,一旦冲突,唯一能作的就是放弃其中一个.从事Web开发不可避免要接触JavaScript,目前最新版本的JavaScript ...
- java8-1-interface接口
Java 8 允许我们使用default关键字,为接口声明添加非抽象的方法实现.这个特性又被称为扩展方法 sample: interface Formula { double calculate(in ...