public class stringBuffer {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
String str1="what is"+" you name";
System.out.println(str1);
//使用+来拼接字符串
StringBuffer str2=new StringBuffer();
str2.append("what");
str2.append(" is");
str2.append(" you");
str2.append(" name");
System.out.println(str2.toString());
//StringBuffer的append方法来拼接字符串,并使用tostring()方法来转换
System.out.println(new StringBuffer().append("what")
.append(" is")
.append(" you")
.append(" name")
.toString());
//无需任何变量拼接字符串并输出
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
String str1="what is"+" you name";
System.out.println(str1);
//使用+来拼接字符串
StringBuffer str2=new StringBuffer();
str2.append("what");
str2.append(" is");
str2.append(" you");
str2.append(" name");
System.out.println(str2.toString());
//StringBuffer的append方法来拼接字符串,并使用tostring()方法来转换
System.out.println(new StringBuffer().append("what")
.append(" is")
.append(" you")
.append(" name")
.toString());
//无需任何变量拼接字符串并输出
}
}
输出结果:
what is you name
what is you name
what is you name