Java SE API
Properties.getProperty()
Get string property or fallback. Java SE API; example uses Java 21-compatible syntax.
Formal Syntax & Structure
java syntaxjava
String getProperty(String key, String defaultValue)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| key | String | Property name |
| defaultValue | String | Fallback value |
Return Value
String
Get string property or fallback.
Working Example
Example Snippetjava
import java.util.*;import java.util.regex.*;import java.nio.*;import java.nio.charset.*;import java.io.*;import javax.xml.XMLConstants;import javax.xml.parsers.*;import org.xml.sax.*;import org.xml.sax.helpers.DefaultHandler;import org.w3c.dom.*;public class Main { public static void main(String[] args) throws Exception { var props = new Properties(); try (var reader = new StringReader("title=café\ncount=3\n")) { props.load(reader); } System.out.println(props.getProperty("title")); System.out.println(Integer.parseInt(props.getProperty("count"))); System.out.println(props.getProperty("mode", "safe")); }}