zoukankan      html  css  js  c++  java
  • HashMap遍历方法

    http://jiankeafei.iteye.com/blog/286017

    在java中使用HashMap是主要有两种遍历方法,代码如下:

    第一种:

    1. HashMap hashmap = new HashMap();
    2. Iterator iterator = hashmap.keySet().iterator();
    3. while (iterator.hasNext()) {
    4.        Object value = hashmap.get(iterator.next());
    5.         }

    第二种:

    1. HashMap hashmap = new HashMap();
    2. Iterator iterator = hashmap.keySet().iterator();           
    3.  while (iter.hasNext()) {
    4.                 Entry entry = (Entry) iter.next();
    5.                 Object value= entry.getValue();
    6.                 Object key =entry.getKey();
    7.                             }

    据说使用第二种方法要比第一种方法效率快,不过没有亲自验证!

  • 相关阅读:
    ASP.NET
    ASP.NET
    MSSQL
    ASP.NET
    HTML+CSS+JS
    HTML+CSS
    ASP.NET、WinForm、C#
    MSSQL
    WinFrom
    线性代数应该这样学一
  • 原文地址:https://www.cnblogs.com/leiqun123/p/4596186.html
Copyright © 2011-2022 走看看