Properties containsKey(Object) in Java

containsKey(Object): This method is available in java.util.Properties class of Java.

Syntax:

boolean java.util.Properties.containsKey(Object key)

This method takes one argument. This method tests if the specified object is a key in this hashtable.

Parameters: One parameter is required for this method.

key: possible key.

Returns: true if and only if the specified object is a key in this hashtable, as determined by the equals method; false otherwise.

Exceptions: NA

Approach

Java

import java.util.Properties;

public class PropertiescontainsKey {
    public static void main(String[] args) {

        Properties properties = new Properties();

        properties.put("Hello", "World");
        properties.put("C++", "Program");
        properties.put("Java", "Program");

        Object key = "C++";

        System.out.println(properties.containsKey(key));
    }
}

Output:

true


No comments:

Post a Comment