• 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中

    }
    }

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

  • 相关阅读:
    Blender基础操作
    反汇编及linux下edb的下载
    混淆矩阵(confusion_matrix)含义
    Python大数据第三次的作业
    Python的DataFrame基础使用
    Python数据标准化
    爬虫之xpath
    luffy项目上线
    爬虫之selenium
    celery
  • 原文地址:https://www.cnblogs.com/curedfisher/p/12418198.html
Copyright © 2020-2023  润新知