Java.util.LinkedHashMap.clear() 方法
描述
java.util.LinkedHashMap.clear() 方法从该映射中删除所有映射。 此调用返回后,映射将为空。
声明
以下是 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:{}

