使用大括号 {} 的 MessageFormat

Ami*_*tha 3 java messageformat

在Java中使用MessageFormat类在字符串中传递不同的变量时

System.out.println(MessageFormat.format("I want to resolve this statement "{  {0}, {1}  }", "this", "this"));  
Run Code Online (Sandbox Code Playgroud)

当您打印此内容时,它将显示 --> { {0}, {1} } 并且由于包裹在大括号中而不会解析带有值的参数。

Mic*_*dis 5

你想要的是这样的:

System.out.println(MessageFormat.format("I want to resolve this statement '{'{0}, {1}'}'", "this", "this"));
Run Code Online (Sandbox Code Playgroud)

输出

我想解决这个陈述{this,this}