package cn.spads.tool.string;
import java.text.MessageFormat;
/**
* 测试字符串连接
* @authorSurmounting
* @versionV1.1.0
* history
* 1.1.0, 2015年9月1日Surmounting初版
* @sinceJava 6.0
*/
public class TestStringConnect {
public static void main(String[] args) {
// 使用字符串连接符
System.out.println("今天是" + 2015 + "年" + 9 + "月" + 1 + "日");
// 使用StringBuilder
System.out.println(new StringBuilder("今天是").append(2015)
.append("年")
.append(9)
.append("月")
.append(1)
.append("日"));
// 使用StringBuffer
System.out.println(new StringBuffer("今天是").append(2015).append("年").append(9).append("月").append(1).append("日"));
// 使用String.format
System.out.println(String.format("今天是%s年%s月%s日", 2015, 9, 1));
// 使用MessageFormat.format
System.out.println(MessageFormat.format("今天是{0}年{1}月{2}日", "2015", "9", "1"));
// 使用String.concat 只能连接字符串
System.out.println("今天是".concat("2015").concat("年").concat("9").concat("月").concat("1").concat("日"));
}
}