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


Java Java.util.LinkedHashMap.clear()用法及代碼示例


描述

這個java.util.LinkedHashMap.clear()方法從此映射中刪除所有映射。此調用返回後,Map將為空。

聲明

以下是聲明java.util.LinkedHashMap.clear()方法

public void clear()

參數

NA

返回值

此方法不返回值。

異常

NA

示例

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

package com.tutorialspoint;

import java.util.*;

public class BitSetDemo {
   public static void main(String[] args) {

      // create a new linked hash map
      LinkedHashMap map = new LinkedHashMap(5);

      // add some values in the map
      map.put("One", 1);
      map.put("Two", 2);
      map.put("Three", 3);

      // print the map
      System.out.println("Map:" + map);

      // clear the map
      map.clear();

      // print the map
      System.out.println("Map:" + map);
   }
}

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

Map:{One=1, Two=2, Three=3}
Map:{}

相關用法


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