Properties keys() in Java

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

Syntax:

Enumeration<Object> java.util.Properties.keys()

This method returns an enumeration of the keys in this hashtable.

Parameters: NA

Returns: an enumeration of the keys in this hashtable.

Exceptions: NA

Approach

Java

import java.util.Enumeration;
import java.util.Properties;

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

        Properties properties = new Properties();

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

        Enumeration<Object> enumeration = properties.keys();

        while (enumeration.hasMoreElements()) {
            System.out.print(enumeration.nextElement() + " ");

        }

    }
}

Output:

Java C++ Hello 

No comments:

Post a Comment