Ruby like string interpolation in Java
Hi,
I am trying to find out if there is any ruby like string interpolation in java...for example :
("where is {$color} coffee {$object},"brown","mug") would give me "where is brown coffee mug"
I have never really worked on ruby myself, but I have heard that its interpolation method makes life really easy when generating dynamic strings or generating queries for a database dynamically.
Thanks!
Re: Ruby like string interpolation in Java
Look at the String class's format() method. It will do String substitutions
Re: Ruby like string interpolation in Java
In addition to what Norm said, check out the printf() method: PrintStream (Java Platform SE 6)
Re: Ruby like string interpolation in Java
I suspect the MessageFormat class is as close as you're likely to get.