java 方法 示例
属性类stringPropertyNames()方法 (Properties Class stringPropertyNames() method)
stringPropertyNames() method is available in java.util package.
java.util包中提供了stringPropertyNames()方法 。
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()方法用于获取此属性列表中存在的所有键,并且此处的键及其所需值是字符串,并且默认属性列表中存在唯一键以在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()方法是一个非静态方法,只能通过类对象访问,如果尝试使用类名称访问该方法,则会收到错误消息。
stringPropertyNames() method does not throw an exception at the time of returning property names.
返回属性名称时, stringPropertyNames()方法不会引发异常。
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.
方法的返回类型为Set ,它返回存在于此属性列表中的键集以及存在于默认列表中的键。
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]
翻译自: https://www.includehelp.com/java/properties-stringpropertynames-method-with-example.aspx
java 方法 示例