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


Java java.util.TreeMap.containsValue()用法及代碼示例


描述

這個containsValue(Object value)如果此映射將一個或多個鍵映射到指定值,則使用方法返回 true。

聲明

以下是聲明java.util.TreeMap.containsValue()方法。

public boolean containsValue(Object value)

參數

valueâ^這是要測試其在該Map中是否存在的值。

返回值

如果存在到此值的映射,則方法調用返回 true,否則返回 false。

異常

NA

示例

下麵的例子展示了 java.util.TreeMap.containsValue() 方法的用法。

package com.tutorialspoint;

import java.util.*;

public class TreeMapDemo {
   public static void main(String[] args) {
      
      // creating tree map 
      NavigableMap<Integer, String> treemap = new TreeMap<Integer, String>();

      // populating tree map
      treemap.put(2, "two");
      treemap.put(1, "one");
      treemap.put(3, "three");
      treemap.put(6, "six");
      treemap.put(5, "five");

      System.out.println("Checking value");
      System.out.println("'three' exists:"+ treemap.containsValue("three"));
   }    
}

讓我們編譯並運行上麵的程序,這將產生以下結果。

Checking value
'three' exists:true

相關用法


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