Parameterized Strings in Java

String.format()

Since Java 5, you can use String.format to parametrize Strings. Example:

String fs;
fs = String.format("The value of the float " +
                   "variable is %f, while " +
                   "the value of the " + 
                   "integer variable is %d, " +
                   " and the string is %s",
                   floatVar, intVar, stringVar);

See http://docs.oracle.com/javase/tutorial/java/data/strings.html

Alternatively, you could just create a wrapper for the String to do something more fancy.

MessageFormat

Per the comment by Max and answer by Affe, you can localize your parameterized String with the MessageFormat class.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)