zoukankan      html  css  js  c++  java
  • 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中

    }
    }

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

  • 相关阅读:
    jsp.图书馆
    jsp第七次作业
    jsp第六次作业
    jsp第四次作业
    JSP第二次作业
    软件测试课堂练习
    Android第六次作业
    Android第五次作业
    Android第四次作业
    Android第三次作业
  • 原文地址:https://www.cnblogs.com/curedfisher/p/12418198.html
Copyright © 2011-2022 走看看