StringBuilder is not thread safe. So, it performs better in situations where thread safety is not required.

StringBuffer is implemented by using synchronized keyword on all methods.

StringBuffer

/*      */   public synchronized StringBuffer append(String string)
/* */ {
/* 197 */ if (string == null) string = String.valueOf(string);
/* 198 */ int adding = string.length();
/* 199 */ int newSize = this.count + adding;
/* 200 */ if (newSize > this.value.length) {
/* 201 */ ensureCapacityImpl(newSize);
/* */ }
/* 203 */ string.getChars(0, adding, this.value, this.count);
/* 204 */ this.count = newSize;
/* 205 */ return this;
/* */ }

StringBuilder

/*      */   public StringBuilder append(String string)
/* */ {
/* 201 */ if (string == null) string = String.valueOf(string);
/* 202 */ int adding = string.length();
/* 203 */ int newSize = this.count + adding;
/* 204 */ if (newSize > this.value.length) {
/* 205 */ ensureCapacityImpl(newSize);
/* */ }
/* 207 */ string.getChars(0, adding, this.value, this.count);
/* 208 */ this.count = newSize;
/* 209 */ return this;
/* */ }

StringBuffer StringBuilder append的更多相关文章

  1. StringBuilder的append、StringBuffer的append和String str = "a"+"b"的区别?

    大家都知道String+String会开销额外的系统资源,粗略的原因是String是不可变类,每一步操作都会返回新的String变量,占用空间及时间. 其实我的理解不是这样的,我们来看看String+ ...

  2. String,StringBuffer,StringBuilder的区别

    public static void main(String[] args) { String str = new String("hello...."); StringBuffe ...

  3. [源码]String StringBuffer StringBudlider(2)StringBuffer StringBuilder源码分析

      纵骑横飞 章仕烜   昨天比较忙 今天把StringBuffer StringBulider的源码分析 献上   在讲 StringBuffer StringBuilder 之前 ,我们先看一下 ...

  4. 关于String StringBuffer StringBuilder

    0. String对象的创建       1.关于类对象的创建,很普通的一种方式就是利用构造器,String类也不例外:String s=new String("Hello world&qu ...

  5. Java之String,StringBuffer,StringBuilder类

    在 java 语言中, 用来处理字符串的的类常用的有 3 个: String.StringBuffer.StringBuilder. 它们的异同点: 1) 都是 final 类, 都不允许被继承; 2 ...

  6. String, StringBuffer, StringBuilder比较

    1.见API: String是不可变的字符序列: StringBuffer是线程安全的,可变的字符序列: StringBuilder是可变的字符序列: StringBuffer与String的区别是S ...

  7. [置顶] String StringBuffer StringBuilder的区别剖析

    这是一道很常见的面试题目,至少我遇到过String/StringBuffer/StringBuilder的区别:String是不可变的对象(final)类型,每一次对String对象的更改均是生成一个 ...

  8. String StringBuffer StringBuilder (转)

    转自:http://www.iteye.com/topic/522167 众所周知,String是由字符组成的串,在程序中使用频率很高.Java中的String是一个类,而并非基本数据类型. 不过她却 ...

  9. StringBuffer使用append提示String concatenation as argument to 'StringBuffer.append()' call

    昨天发现一个IDE提示: String concatenation as argument to 'StringBuffer.append()' call less... (Ctrl+F1) Repo ...

随机推荐

  1. springcloud与dubbo对比:

    我们直接将结论先列出来,然后逐个分析: 本博客借鉴此文章:http://blog.csdn.net/shuijieshuijie/article/details/53133082 打个不恰当的比喻: ...

  2. Golang的字符编码介绍

    Golang的字符编码介绍 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. Go里面内建仅支持UTF8字符串编码,因此如果你用fmt.Printf之类的函数无法将GBK,GB2312 ...

  3. 函数和常用模块【day05】:装饰器前奏(一)

    本节内容 定义 原则 实现装饰器的储备知识 函数及变量 高阶函数 一.定义 1.装饰器:本质是函数. 2.功能:用来装饰其他函数,顾名思义就是,为其他的函数添加附件功能的. 二.原则 不能修改被装饰函 ...

  4. OpenStack API部分高可用配置(二)

    一.安装与配置HAProxy 1.调整内核参数,允许绑定VIP: vim /etc/sysctl.conf [内容] net.ipv4.ip_nonlocal_bind=1 sysctl -p 2.安 ...

  5. cin,cout,printf,scanf效率对比

    From:http://www.cnblogs.com/killerlegend/p/3918452.html Author:KillerLegend Date:2014.8.17 杭电OJ之3233 ...

  6. 何凯文每日一句打卡||DAY14

  7. BZOJ4818 序列计数

    4818: [Sdoi2017]序列计数 Time Limit: 30 Sec  Memory Limit: 128 MB Description Alice想要得到一个长度为n的序列,序列中的数都是 ...

  8. 【Python】Flask系列-cookie和session笔记

    cookie: 1.cookie出现的原因:在网站中,http请求是无状态的.也就是说即使第一次和服务器连接后并且登录成功后,第二次请求服务器依然不能知道当前请求是哪个用户.cookie的出现就是为了 ...

  9. request_irq与request_threaded_irq

    /* * Allocate the IRQ */ #if 0 retval = request_irq(uap->port.irq, pl011_int, 0, "uart-pl011 ...

  10. mysql+mycat压力测试一例【转】

    前言 有很多人担心生产系统上新东西的程序怕压力跟不上和稳定性不行,是的,大家都怕,所以领导要求做一次压力测试,我个人也觉得是有必要的. 如果按原理来说,mycat如果不做分片,纯粹只是代理的话,他所做 ...