StringBuilder的构造方法和append方法
生活随笔
收集整理的這篇文章主要介紹了
StringBuilder的构造方法和append方法
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
package com.learn.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中}
}
?
超強干貨來襲 云風專訪:近40年碼齡,通宵達旦的技術人生總結
以上是生活随笔為你收集整理的StringBuilder的构造方法和append方法的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: System类的常用方法
- 下一篇: StringBuilder的toStri