Properties remove(Object) in Java

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

Syntax:

Object java.util.Properties.remove(Object key)

This method takes one argument. This method removes the key (and its corresponding value) from this hashtable.

Parameters: One parameter is required for this method.

key: the key that needs to be removed.

Returns: the value to which the key had been mapped in this hashtable, or null if the key did not have a mapping.

Exceptions: NA

Approach

Java

import java.util.Properties;

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

        Properties properties = new Properties();

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

        Object key = "Hello";

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

Output:

World


No comments:

Post a Comment