public class StringBufferDemo {
    public static void main(String[] args){
        String s1="Hellow"+", "+"world";
        System.out.println(s1);
        
        //StringBuffer对象
        StringBuffer sb2=new StringBuffer();
        sb2.append("Hellow");
        sb2.append(',');
        sb2.append(' ');
        sb2.append("World");
        
        //将StringBuffer对象转换成String
        String s2=sb2.toString();
        System.out.println(s2);
        
        //更简明的方式(典型的“Real-World”Java)
        StringBuffer sb3=new StringBuffer().append("Hellow").append(',').append(' ').append("World");
        System.out.println(sb3.toString());
        
        //读者练习:不用任何中间变量,将上面的工作重复一遍
    }
帮忙最后的读者练习,

解决方案 »

  1.   

    System.out.println("Hellow"+", "+"world");
      

  2.   

    System.out.println(new String("hello")+ new String("world") );
    System.out.println(new StringBuffer().append("hello").append("world"));
    类似这样吗,,
      

  3.   

    System.out.println(new StringBuffer().append("Hellow").append(',').append(' ').append("World"));
      

  4.   

    这一节是讲StringBuilder的
    第一个不会就这么简单吧,第二个连字符串都不是,println()不能输出StringBuffer对象吧
      

  5.   

    println()不能直接输出StringBuffer对象吧