Return a default value if the specified property does not exist in Java

Description

The following code shows how to return a default value if the specified property does not exist.

Example


// w  ww  .  j  a v a2  s .  c o  m
public class Main {

  public static void main(String[] args){
     System.out.println(System.getProperty("password","defaultPassword")); 
  }

}

The code above generates the following result.





















Home »
  Java Tutorial »
    Development »




Java Algorithms
Java Clipboard
Java Compiler
Java Desktop
Java Virtual Machine
Java Math
OS
Random
Java Robot
Java RuntimeMXBean
Java Timer
Java UUID
Java Internationalization