Home » Java programming language

Java Properties stringPropertyNames() Method with Example

Properties Class stringPropertyNames() method: Here, we are going to learn about the stringPropertyNames() method of Properties Class with its syntax and example.
Submitted by Preeti Jain, on March 21, 2020

Properties Class stringPropertyNames() method

  • stringPropertyNames() method is available in java.util package.
  • stringPropertyNames() method is used to get all the key exists in this Property list and here the key and its desired value are string along with unique key exists in the default property list to be viewed in a Set.
  • stringPropertyNames() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.
  • stringPropertyNames() method does not throw an exception at the time of returning property names.

Syntax:

    public Set stringPropertyNames();

Parameter(s):

  • It does not accept any parameter.

Return value:

The return type of the method is Set, it returns set of keys exist in this property list along with the key exists in the default list.

Example:

// Java program to demonstrate the example 
// of Set stringPropertyNames()
// method of Properties

import java.io.*;
import java.util.*;

public class StringPropertyNamesOfProperties {
 public static void main(String arg[]) throws Exception {
  // Instantiate Properties object
  Properties prop = new Properties();

  prop.put("10", "C");
  prop.put("20", "C++");
  prop.put("30", "JAVA");
  prop.put("40", "PHP");
  prop.put("50", "SFDC");

  // Get all the properties of
  // this object in a set
  Set set = prop.stringPropertyNames();

  // Display Set View
  System.out.println("prop.stringPropertyNames(): " + set);
 }
}

Output

prop.stringPropertyNames(): [50, 40, 30, 20, 10]



Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.