java.util.WeakHashMap.size() 方法
描述
size() 方法用于返回此映射中键值映射的数量。
声明
以下是 java.util.WeakHashMap.size() 方法的声明。
public int size()
参数
NA
返回值
方法调用返回此映射中键值映射的数量。
异常
NA
示例
下面的例子展示了 java.util.WeakHashMap.size() 方法的使用。
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>();
// 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 the size of the Map
System.out.println("Map size: "+weakHashMap.size());
}
}
让我们编译并运行上面的程序,这将产生以下结果.
Putting values into the Map Map size: 3

