MessageFormat.format使用
package com.jeagine.controller.uapp;
import java.text.MessageFormat;
/**
* @Author: zengwei
* @Date: 2019/4/28 10:23
* @Version 1.0
*/
public class Test {
public static void main(String[] args) {
//加 \ 是为了不转义而显示 " 字符
String message ="我是\"{0}\",年龄是{1},我来自{2}";
Object [] array = {"华为","66","东莞松湖"};
String format = MessageFormat.format(message, "小米", "23", "M78星云");
String format1 = MessageFormat.format(message, array);
System.out.println(format);
System.out.println(format1);
}
}
我是"小米",年龄是23,我来自M78星云
我是"华为",年龄是66,我来自东莞松湖