StringBuilder就像PreparedStatement一样

Ana*_*oly 0 java stringbuilder

有没有办法创建像我们创建PreparedStatements的字符串?我的意思是用'?'创建整个字符串 我需要稍后插入值,然后根据条件插入此值.在StringBuilder中,我没有找到这样的功能,只是通过offset附加或插入.

lau*_*une 5

这是来自MessageFormat的javadoc:

 int planet = 7;
 String event = "a disturbance in the Force";

 String result = MessageFormat.format(
     "At {1,time} on {1,date}, there was {2} on planet {0,number,integer}.",
     planet, new Date(), event);
Run Code Online (Sandbox Code Playgroud)

输出是:

 At 12:30 PM on Jul 3, 2053, there was a disturbance in the Force on planet 7.
Run Code Online (Sandbox Code Playgroud)

你可以看到简单的插入是可能的({2}),但也可以是更复杂的插入.