Home »
Java programming language
Java ResourceBundle containsKey() Method with Example
ResourceBundle Class containsKey() method: Here, we are going to learn about the containsKey() method of ResourceBundle Class with its syntax and example.
Submitted by Preeti Jain, on March 24, 2020
ResourceBundle Class containsKey() method
- containsKey() method is available in java.util package.
- containsKey() method is used to check whether the given key element (key_ele) exists or not exists in this ResourceBundle or its super bundles.
- containsKey() 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.
- containsKey() method may throw an exception at the time of checking the existence of the given element.
NullPointerException: This exception may throw when the given parameter is null exists.
Syntax:
public boolean containsKey(String key_ele);
Parameter(s):
- String key_ele – represents the key element of this ResourceBundle.
Return value:
The return type of this method is boolean, it returns true when the given key element exists in this ResourceBundle or its super bundle otherwise it returns false.
Example:
// Java program to demonstrate the example
// of boolean containsKey(String key_ele) method
// of ResourceBundle
import java.util.*;
public class ContainsKeyOfResourceBundle {
public static void main(String[] args) {
// Instantiates ResourceBundle with
// some locale
ResourceBundle rb = ResourceBundle.getBundle("IncludeHelp...", Locale.FRANCE);
// By using containsKey() method isto
// check whether the given key exists or
// not in this ResourceBundle
boolean status = rb.containsKey("IncludeHelp...");
// Display status
System.out.println("rb.containsKey(IncludeHelp...): " + status);
}
}
Output
rb.containsKey(IncludeHelp...): true