For example I want to implement class with method
public class Logger {
public void info(String message, String[] params) {
}
}
If input is
new Logger().info("Info: param1 is ? , param2 is ?", new String[] {"a", "b"});
Output must be
Info: param1 is a , param2 is b
What is the easiest way to implement it?
You can use the String.format(String format, Object ... args)
method for this. Instead of using a ?
, you can do C style %x
format, where x
can be d
(for int), s
(for string), etc.
Also, you can view the Formatter.format
class method. It shows you all formatting flags acceptale for formatting (String.format()
method uses Formatter
to do the formatting).