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


Java 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]

相關用法


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