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);
    
    }
    
    }
  • 相关阅读:
    进程通信
    python模块成像库pillow
    python模块IO
    python模块StringIO和BytesIO
    DJango重写用户模型
    DJango模型Meta选项详解
    DJango中事务的使用
    批量删除文件
    批量修改文件名字或后缀
    自定义中间件实现插拔设计
  • 原文地址:https://www.cnblogs.com/yuyue2014/p/4206597.html
Copyright © 2011-2022 走看看