replacing string with dynamic avalues java code example

Example 1: replacing string with dynamic avalues java

System.out.printf("%S-%S-%S\n", ""+17, ""+06, ""+0001);

Example 2: replacing string with dynamic avalues java

String a = "{YY}-{MM}-{SEQNO}";
a = a.replace("YY", "17").replace("MM", "06").replace("SEQNO", "0001");
System.out.println(a);
//Output:  {17}-{06}-{0001}

Example 3: replacing string with dynamic avalues java

String s = java.text.MessageFormat.format("I would like to have {0} KG of rice and {1} Litre of Milk. I only have ${2}, is this sufficient?",new String[]{"100","5","50"});
System.out.println(s);

Tags:

Misc Example