Friday, November 18, 2011

String substitution



To substitute words in String.

String exampleString = " There is %s disturbance in planet %s ";
String newString = String.format(exampleString,new Object[]{"a","mars."});
System.out.println(newString);

Output :  There is a disturbance in planet mars.

Alternatively you can also use the MessageFormatClass

http://download.oracle.com/javase/6/docs/api/java/text/MessageFormat.html