使用MessageFormat占位符的替换
package com.utils.test; import java.text.MessageFormat; import org.junit.Test; /** * 使用MessageFormat占位符的替换 * @author Administrator * */ public class MessageFormatTest { @Test public void fun(){ String str = "你好{0},欢迎来到{1}"; /* * public static String format(String pattern, Object... arguments) * 创建具有给定模式的 MessageFormat,并用它来格式化给定的参数。 */ String strs = MessageFormat.format(str, "kitty","JavaWorld"); System.out.println(strs); }
/*
输出结果:
你好kitty,欢迎来到JavaWorld
*/ }