java enummap_Java EnumMap containsValue()方法与示例
java enummap
EnumMap類containsValue()方法 (EnumMap Class containsValue() method)
containsValue() method is available in java.util package.
containsValue()方法在java.util包中可用。
containsValue() method is used to check whether the given value element (val_ele) maps one or more than one key associated or not of this enum map.
containsValue()方法用于檢查給定值元素( val_ele )是否映射一個或多個與該枚舉映射關聯的鍵。
containsValue() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.
containsValue()方法是一個非靜態方法,只能通過類對象訪問,如果嘗試使用類名稱訪問該方法,則會收到錯誤消息。
containsValue() method does not throw an exception at the time of checking value mappings.
containsValue()方法在檢查值映射時不會引發異常。
Syntax:
句法:
public boolean containsValue(Object val_ele);Parameter(s):
參數:
Object val_ele – represents the value element (val_ele) whose presence is to be checked.
對象val_ele –表示要檢查其值的值元素(val_ele)。
Return value:
返回值:
The return type of this method is boolean, it returns true when this enum map have one or more keys for the given value element (val_ele) otherwise it returns false.
此方法的返回類型為boolean ,當此枚舉映射具有給定值元素(val_ele)的一個或多個鍵時,它返回true,否則返回false。
Example:
例:
// Java program to demonstrate the example // of boolean containsValue(Object val_ele) method // of EnumMapimport java.util.*;public class ContainsValueOfEnumMap {public enum Colors {RED,BLUE,PINK,YELLOW};public static void main(String[] args) {// We are creating EnumMap objectEnumMap < Colors, String > em =new EnumMap < Colors, String > (Colors.class);// By using put() method is to// add the linked values in an// EnumMapem.put(Colors.RED, "1");em.put(Colors.BLUE, "2");em.put(Colors.PINK, "3");em.put(Colors.YELLOW, "4");// Display EnumMapSystem.out.println("EnumMap :" + em);// By using containsValue() method isto// check whether this EnumMap contains// atleast one key element associated for the// given value element or not in an EnumMapboolean status = em.containsValue("3");// Display status of EnumMapSystem.out.println("em.containsValue(3): " + status);} }Output
輸出量
EnumMap :{RED=1, BLUE=2, PINK=3, YELLOW=4} em.containsValue(3): true翻譯自: https://www.includehelp.com/java/enummap-containsvalue-method-with-example.aspx
java enummap
總結
以上是生活随笔為你收集整理的java enummap_Java EnumMap containsValue()方法与示例的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: php分布式的锁,laravel分布式并
- 下一篇: python整数转换字符串_Python