目录

String getProperty(String key, String defaultValue)

描述 (Description)

java.util.Properties.getProperty(String key,String defaultValue)方法在此属性列表中搜索具有指定键的属性。 如果在此属性列表中找不到该键,则会检查默认属性列表及其默认值(递归)。 如果未找到该属性,则该方法返回默认值参数。

声明 (Declaration)

以下是java.util.Properties.getProperty()方法的声明

public String getProperty(String key,String defaultValue)

参数 (Parameters)

  • key - 哈希表键。

  • defaultValue - 默认值。

返回值 (Return Value)

此方法返回具有指定键值的此属性列表中的值。

异常 (Exception)

NA

例子 (Example)

以下示例显示了java.util.Properties.getProperty()方法的用法。

package com.iowiki;
import java.util.*;
public class PropertiesDemo {
   public static void main(String[] args) {
      Properties prop = new Properties();
      // add some properties
      prop.put("Height", "200");
      prop.put("Width", "150");
      prop.put("Scannable", "true");
      // get two properties and print them
      System.out.println("" + prop.getProperty("Scannable","false"));
      System.out.println("" + prop.getProperty("Width","150"));
   }
}

让我们编译并运行上面的程序,这将产生以下结果 -

true
150
↑回到顶部↑
WIKI教程 @2018