coffee_cn

博客园 首页 新随笔 联系 订阅 管理

 

https://www.runoob.com/java/java-map-interface.html

实例

下面的例子来解释Map的功能

import java.util.*;

public class CollectionsDemo {

   public static void main(String[] args) {
      Map m1 = new HashMap(); 
      m1.put("Zara", "8");
      m1.put("Mahnaz", "31");
      m1.put("Ayan", "12");
      m1.put("Daisy", "14");
      System.out.println();
      System.out.println(" Map Elements");
      System.out.print("\t" + m1);
   }
}

以上实例编译运行结果如下:

Map Elements
        {Mahnaz=31, Ayan=12, Daisy=14, Zara=8}
posted on 2019-09-23 11:36  coffee  阅读(167)  评论(0编辑  收藏  举报