Java Properties.getProperty(String key, String defaultValue)

Syntax

Properties.getProperty(String key, String defaultValue) has the following syntax.

public String getProperty(String key,   String defaultValue)

Example

In the following code shows how to use Properties.getProperty(String key, String defaultValue) method.


/*www  .j a  v a 2s. co m*/
import java.util.Properties;

public class Main {

   public static void main(String[] args)  throws Exception{
      Properties prop = new Properties();

  
      prop.put("Chapter Count", "200");
      prop.put("Tutorial Count", "150");
      prop.put("tutorial", "java2s.com");
      prop.put("Runnable", "true");

      // get two properties and print them
      System.out.println(prop.getProperty("Runnable","false"));
      System.out.println(prop.getProperty("Tutorial Count","150"));

   }
}

The code above generates the following result.