java连接字符串

来源:互联网 发布:设计图纸软件下载 编辑:程序博客网 时间:2024/05/18 02:20
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());
      //无需任何变量拼接字符串并输出
      
      
}


}

输出结果:

                what is you name
what is you name
what is you name

0 0
原创粉丝点击