java.util.WeakHashMap.values() 方法
描述
values() 方法用于返回此映射中包含的值的集合视图。
声明
以下是 java.util.WeakHashMap.values() 方法的声明。
public Collection<V> values()
参数
NA
返回值
该方法调用返回此映射中包含的值的集合视图。
异常
NA
示例
下面的例子展示了 java.util.WeakHashMap.values() 方法的使用。
package com.tutorialspoint;
import java.util.*;
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 values: "+weakHashMap);
Collection col = weakHashMap.values();
System.out.println("Collection values: "+col);
}
}
让我们编译并运行上面的程序,这将产生以下结果.
Putting values into the Map
Map values: {1=first, 2=two, 3=three}
Collection values: [first, two, three]

