Properties getProperty(String) in Java

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

Syntax:

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

This method takes one argument. This method searches for the property with the specified key in this property list.

Note: The method returns null if the property is not found.

Parameters: One parameter is required for this method.

key: the property key.

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

Exceptions: NA

Approach

Java

import java.util.Properties;

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

        Properties properties = new Properties();

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

        String key = "Hello";

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

Output:

World


No comments:

Post a Comment