void clear()
描述 (Description)
java.util.LinkedHashMap.clear()方法从此映射中删除所有映射。 此调用返回后,映射将为空。
声明 (Declaration)
以下是java.util.LinkedHashMap.clear()方法的声明
public void clear()
参数 (Parameters)
NA
返回值 (Return Value)
此方法不返回值。
异常 (Exception)
NA
例子 (Example)
以下示例显示了java.util.LinkedHashMap.clear()方法的用法。
package com.iowiki;
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:{}