當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Java java.util.WeakHashMap.isEmpty()用法及代碼示例


描述

這個isEmpty()如果此映射不包含鍵值映射,則使用方法返回 true

聲明

以下是聲明java.util.WeakHashMap.isEmpty()方法。

public boolean isEmpty()

參數

NA

返回值

如果此映射不包含鍵值映射,則方法調用返回 true。

異常

NA

示例

下麵的例子展示了 java.util.WeakHashMap.isEmpty() 方法的用法。

package com.tutorialspoint;

import java.util.Map;
import java.util.WeakHashMap;

public class WeakHashMapDemo {
   public static void main(String[] args) { 
      Map<String, String> weakHashMap = new WeakHashMap<String, String>();

      // check map contents
      System.out.println("Checking the map entries");
      System.out.println("Map is empty:"+weakHashMap.isEmpty());

      // put keys and values in the Map
      System.out.println("Putting values into the Map");
      weakHashMap.put("1", "first");
      weakHashMap.put("2", "two");
      weakHashMap.put("3", "three");

      // checking Map
      System.out.println("Map is empty:"+weakHashMap.isEmpty());
   }    
}

讓我們編譯並運行上麵的程序,這將產生以下結果。

Checking the map entries
Map is empty:true
Putting values into the Map
Map is empty:false

相關用法


注:本文由純淨天空篩選整理自 java.util.WeakHashMap.isEmpty() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。