集册 Java实例教程 获取HashMap的大小

获取HashMap的大小

欢马劈雪     最近更新时间:2020-01-02 10:19:05

573
提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
获取哈希映射的大小


import java.util.HashMap;
/**
n o w  j a v a  . c o m
**/

 

public class Main {

 

  public static void main(String[] args) {

    HashMap hMap = new HashMap();

   

    System.out.println("Size of HashMap : " + hMap.size());

   

    //add key value pairs to HashMap using put method

    hMap.put("1","One");

    hMap.put("2","Two");

    hMap.put("3","Three");

    System.out.println("Size of HashMap after addition : " + hMap.size());

   

    //remove one element from HashMap using remove method

    Object obj = hMap.remove(
展开阅读全文