




package com.njwbhz.March.week1.part0301;
/**
* @author FairyKunKun
* @since 2022/3/1
*/
public class TestStringBuffer1 {
public static void main(String[] args) {
//sout在输出拼接语句时,会产生大量的对象,性能很低
System.out.println();
//StringBuffer的基本使用方法
// StringBuffer stringBuffer = new StringBuffer("hello");
//用StringBuffer构造一个字符序列
StringBuffer stringBuffer = new StringBuffer();
//对象名.append()给stringBuffer对象追加内容
stringBuffer.append("我的姓名:张三");
//对象名.hashCode()输出stringBuffer对象的地址
System.out.println(stringBuffer.hashCode());//1163157884
//输出对象的内容
System.out.println(stringBuffer);//我的姓名:张三
//对象名.append()给stringBuffer对象追加内容
stringBuffer.append("我的年龄:18");
//对象名.hashCode()输出stringBuffer对象的地址
System.out.println(stringBuffer.hashCode());//1163157884
//输出对象的内容
System.out.println(stringBuffer);//我的姓名:张三我的年龄:18
//将stringBuffer对象拆箱成string类型
String info = stringBuffer.toString();
//输出info的内容
System.out.println(info);//我的姓名:张三我的年龄:18
}
}