import java.text.MessageFormat;
System.out.println(MessageFormat.format("start={0}, end={1} ", "22222", "333333"));
public static String joinXmlElement(String element, String value) {
return MessageFormat.format("<{0}>{1}</{0}>\n", element, value);
}
public static void main(String[] args) {
System.out.println(joinXmlElement("msg", "我爱你"));
}
[size=medium]输出:<msg>我爱你</msg>[/size]
本文介绍了一个使用Java进行字符串格式化的方法,并演示了如何通过MessageFormat类实现XML元素的动态拼接。具体展示了如何将变量值插入到预定义的XML模板中。
6701

被折叠的 条评论
为什么被折叠?



