Java中的内联字符串替换?

tib*_*bon 2 ruby java string processing concatenation

我在Processing中做了一些工作,基本上是Java.我通常只使用Ruby工作,并且我已经习惯了很多相当优雅和漂亮的代码约定.

如果我有一个字符串,我想插入其他字符串,在Java中最好的方法是什么?

在Ruby中,我通常做这样的事情(每个变量都是一个字符串):

p "The #{person_title} took a #{mode_of_transit} to the #{holiday_location} for a nice #{verb} in the #{noun}"
Run Code Online (Sandbox Code Playgroud)

在Java中我需要手动连接它们,如下所示:

println("The " + personTitle + " took a " + modeOfTransit + " to the " holidayLocation + for a nice " + verb + " in the " + noun)
Run Code Online (Sandbox Code Playgroud)

这对我来说感觉不对.它有效,但它并不顺畅.有没有办法在Java中这样做?

pru*_*wan 7

最接近的是:

 String s = String.format("The %s took a %s to the %s for a nice %s in the %s", personTitle, modeOfTransit, holidayLocation, verb, noun);
Run Code Online (Sandbox Code Playgroud)