String类型与StringBuffer类型的转换:

StringBuffer转为String

1. StringBuffer类自动重写publicString toString(),返回的是string类型;

    例:String str2 = buffer3.toString();

2. 通过string类的构造方法:publicString(StringBuffer buffer)

例:StringBuffer  buffer3 = newStringBuffer();

String s= new String(buffer3);

String转为StringBuffer

1. 构造方法。publicStringBuffer(String str)

例:StringBuffersb1 = newStringBuffer("abc");

2. append方法。public StringBuffer append(String str)

    例:StringBuffer  buffer3 = newStringBuffer();

        String str = new “java”;

buffer3.append(str);

;