复习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 遍历的几种方法的更多相关文章

  1. map遍历的四种方法

    public static void main(String[] args) { Map<String, String> map = new HashMap<String, Stri ...

  2. Map遍历的几种方法

    查看Map自带API map遍历方法: public static void main(String[] args) { Map<Integer,String> map = new Has ...

  3. (转载)Java中如何遍历Map对象的4种方法

    在Java中如何遍历Map对象 How to Iterate Over a Map in Java 在java中遍历Map有不少的方法.我们看一下最常用的方法及其优缺点. 既然java中的所有map都 ...

  4. map遍历的四种方式

    原文 http://blog.csdn.net/dayanxuqun/article/details/26348277 以下是map遍历的四种方式: // 一.推荐只用value的时候用,都懂的... ...

  5. JavaScript遍历对象4种方法和遍历数组的3种方式 代码

    //遍历对象 4种方法 //Object.keys(obj).forEach() console.log("keys...遍历</br>") var obj1 = { ...

  6. Map集合遍历的2种方法

    Map是一个集合的接口,是key-value相映射的集合接口,集合遍历的话,需要通过Iterator迭代器来进行. Iterator是什么东西: java.util包下的一个接口: 对 collect ...

  7. 遍历Map key-value的两种方法

    以前遍历Map key-value比较习惯的方式是先获取Map中的所有key值,然后根据key,依次从Map中去数据,基本方式如下: Map<String,String> testData ...

  8. map集合遍历的五种方法

    package com.jackey.topic; import java.util.ArrayList;import java.util.HashMap;import java.util.Itera ...

  9. Map<String, String> 遍历的四种方法

    Map<String, String> map = new HashMap<String, String>(); map.put("key1", " ...

随机推荐

  1. codeforces Round #258(div2) C解题报告

    C. Predict Outcome of the Game time limit per test 2 seconds memory limit per test 256 megabytes inp ...

  2. A. Music(Codeforces Round #315 (Div. 2) 求最大的容纳量)

    A. Music time limit per test 2 seconds memory limit per test 256 megabytes input standard input outp ...

  3. laravel接口设计

    在各种公共方法都设计好,软件安装成功的条件下 routes/web.php中路由信息如下 <?php /* |------------------------------------------ ...

  4. spring的bean管理(注解和配置文件混合使用)

    1.建三个类,在一个类中引用其他两个类 import javax.annotation.Resource; import org.springframework.beans.factory.annot ...

  5. JavaScript Simple

    ylbtech-JavaScript: 1.返回顶部 1.   2. 2.返回顶部   3.返回顶部   4.返回顶部   5.返回顶部     6.返回顶部   作者:ylbtech出处:http: ...

  6. 关于阿里云oss

    这两天抽时间看了一下阿里云oss,阿里云oss是阿里为大数据推出的开放存储服务,为多种语言预留出了接口,下面是我对php接口的一点理解. 当注册了阿里云oss账号时会得到接口,在config里面填上这 ...

  7. Codeforces Round #445

    ACM ICPC 每个队伍必须是3个人 #include<stdio.h> #include<string.h> #include<stdlib.h> #inclu ...

  8. hiho一下 第172周

    题目1 : Matrix Sum 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 You are given an N × N matrix. At the beginn ...

  9. img和div的宽度不一样问题和li之间空隙问题的解决方案

    img和div宽度不一致问题 今天写代码,遇到一个小问题,我把一张图片放进一个div里,然后没有设置任何的padding和margin,但是发现图片和div的高度不一样,在img的下方出现了3px的空 ...

  10. 在YII2中使用memcached

    一.在本地安装Memcached服务器和安装memcached扩展 http://www.cnblogs.com/songziqing/p/5896742.html http://www.cnblog ...