Properties getProperty(String, String) in Java

getProperty(String, String): This method is available in java.util.Properties class of Java.

Syntax:

String java.util.Properties.getProperty(String key, String defaultValue)

This method takes two arguments. This method searches for the property with the specified key in this property list.

Note: The method returns the default value argument if the property is not found.

Parameters: Two parameters are required for this method.

key: the hashtable key.

defaultValue: a  default value.

Returns: the value in this property list with the specified key value.

Exceptions: NA

Approach

Java

import java.util.Properties;

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

        Properties properties = new Properties();

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

        String key = "key", defaultValue = "value";

        System.out.println(properties.getProperty(key,
defaultValue));
    }
}

Output:

value


No comments:

Post a Comment