zoukankan      html  css  js  c++  java
  • Java—Map.Entry

    Map是java中的接口,Map.Entry是Map的一个内部接口。

    Map提供了一些常用方法,如keySet()、entrySet()等方法。

    keySet()方法返回值是Map中key值的集合;entrySet()的返回值也是返回一个Set集合,此集合的类型为Map.Entry。

    Map.Entry是Map声明的一个内部接口,此接口为泛型,定义为Entry<K,V>。它表示Map中的一个实体(一个key-value对)。接口中有getKey(),getValue方法。

     
    
    import java.util.HashMap;
    
    import java.util.Iterator;
    
    import java.util.Map.Entry; 
    
    import java.util.Map; 
    
     
    
    public class hello {
    
    public static void main(String[] args){
    
    hashMapTest();
    
     
    
    }
    
     
    
    public static void hashMapTest() {
    
    System.out.println("----------------hashMapTest---------------");
    
     
    
    Map<String,String> map1 = new HashMap<String,String>(); 
    
    map1.put("1", "A");
    
    map1.put("2", "B");
    
    map1.put("3", "C");
    
    map1.put("4", "D");
    
    map1.put("5", "E");
    
    map1.put("6", "F");
    
     
    
    Iterator<Entry<String, String>> it = map1.entrySet().iterator();
    
    while(it.hasNext()){
    
    Map.Entry<String,String> e = (Map.Entry<String,String>) it.next();
    
    System.out.println(e.getKey() + " : " + e.getValue()); 
    
    }
    
     
    
    System.out.println(map1);
    
    }
    
    }
  • 相关阅读:
    组合模式
    迭代器模式
    模板方法模式
    外观模式
    适配器模式
    运行mysql时,提示Table ‘performance_schema.session_variables’ doesn’t exist
    idea maven 打包 引用本地jar
    centos7 安装redis
    centos7 防火墙
    linux 常用命令
  • 原文地址:https://www.cnblogs.com/yuyue2014/p/4206597.html
Copyright © 2011-2022 走看看