Collection

来源:互联网 发布:阿里云域名注册流程 编辑:程序博客网 时间:2024/06/09 14:32

 Map.Entry<K,V>的使用

获得映射项引用的唯一 方法是通过此 collection 视图的迭代器来实现。

Map<String, Employee> staff = new HashMap<String, Employee>();
      staff.put("144-25-5464", new Employee("Amy Lee"));
      staff.put("567-24-2546", new Employee("Harry Hacker"));
      staff.put("157-62-7935", new Employee("Gary Cooper"));
      staff.put("456-62-5527", new Employee("Francesca Cruz"));

      for (Map.Entry<String, Employee> entry : staff.entrySet())
      {
         String key = entry.getKey();
         Employee value = entry.getValue();
         System.out.println("key=" + key + ", value=" + value);
      }

原创粉丝点击