StringBuilder类

 

 

 

 =====================================================================================================================

2.String与StringBuilder原理对比

 

 =========================================================================================================================

3.StringBuilder的构造方法和api

 

Demo02StringBuilder.java

package com.itheima.demo06StringBuilder;
/*
StringBuilder的常用方法:
public StringBuilder append(...):添加任意类型数据的字符串形式,并返回当前对象自身。
*/
public class Demo02StringBuilder {
public static void main(String[] args) {
//创建StringBuilder对象
StringBuilder bu = new StringBuilder();
//使用append方法往StringBuilder中添加数据
//append方法返回的是this,调用方法的对象bu,this==bu
//StringBuilder bu2 = bu.append("abc");//把bu的地址赋值给了bu2
//System.out.println(bu);//"abc"
//System.out.println(bu2);//"abc"
//System.out.println(bu==bu2);//比较的是地址 true

//使用append方法无需接收返回值
// bu.append("abc");
// bu.append(1);
// bu.append(true);
// bu.append(8.8);
// bu.append('中');
// System.out.println(bu);//abc1true8.8中

/*
链式编程:方法返回值是一个对象,可以继续调用方法
*/
System.out.println("abc".toUpperCase().toLowerCase().toUpperCase().toLowerCase());
bu.append("abc").append(1).append(true).append(8.8).append('中');
System.out.println(bu);//abc1true8.8中

}
}

 ===================================================================================================================

 

posted @ 2020-03-05 07:50  Curedfisher  阅读(100)  评论(0编辑  收藏  举报