最近用到这个,通过看jdk1.8的中文文档,发现中文版翻译的乱七八糟还不如看原版
然后在IDE中看MessageFormat的 源码,大概看懂了
其意思就是,这个是用来规范格式的,把字符串按照规定的格式拼接起来
使用静态方法format()
String result = MessageFormat.format("{0} -> {1}", "Hello", "world") // Hello -> world
放大招
package Socket_Thread.heimaLiaotian;
import java.text.MessageFormat;
public class MessageFormatDemo
{
public static void main(String[] args) {
StringBuilder sb = new StringBuilder();
String classSample = MessageFormat.format(Constant.classSample,"电脑");
sb.append(Constant.sb0+"n");
sb.append(classSample);
System.out.println(sb);
}
}
class Constant{
public static StringBuilder sb0 = new StringBuilder("n" +
"n" +
" n" +
" n" +
" n" +
" n" +
" n" +
" ");
static String classSample =
"n" +
" n" +
" ";
}
参考链接:
https://blog.csdn.net/m0_52571715/article/details/110356346
IDE中MessageFormat源码注释



