In java based application most of the times we externalize the constant messages through property files.This property file working in the concept of key value pairs.
There could be a scenario to pass dynamic values in property values. Lets see how can we do that?

First we need to add the place holders in property file. Content of myfile property file looks like below

loginMessage=Welcome {0} your now in {1}



We added two place holders in message above and we can add many place holders based on the requirement. Later this place holders will be replaced with dynamic values. Now i wanted to replace {0} with Raj and {1} with india.

import java.io.File;
import java.io.FileInputStream;
import java.text.MessageFormat;
import java.util.Properties;

public class Test {

  /**
   * @param args
   */
  public static void main(String[] args) {
      try{
      Properties props = new Properties();
      FileInputStream stream=new FileInputStream(new File("F://myfile.properties"));
      props.load(stream);
      String message = props.getProperty("loginMessage");
      String welcome = MessageFormat.format(message, "Raj","India");
      System.out.println(welcome);
      }catch(Exception e){
   
      }
  }

}


Final output:
Welcome Raj your now in India