Properties prop = new Properties(); prop.setProperty("name", "John"); prop.setProperty("age", "25"); SetkeySet = prop.keySet(); System.out.println(keySet); // prints [age, name]
Properties prop = new Properties(); FileInputStream input = new FileInputStream("config.properties"); prop.load(input); SetIn this example, we create a Properties object and load properties from a file named "config.properties" using FileInputStream. We then call the keySet() method and print the output, which is a set of keys present in the config.properties file. These code examples use the java.util package library.keySet = prop.keySet(); System.out.println(keySet); // prints all the keys in the config.properties file