博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
JDK源码阅读--StringBuffer
阅读量:7143 次
发布时间:2019-06-29

本文共 1577 字,大约阅读时间需要 5 分钟。

 

 

public final class StringBuffer extends AbstractStringBuilder implements java.io.Serializable, CharSequence
1 /**2      * A cache of the last value returned by toString. Cleared3      * whenever the StringBuffer is modified.4      */5     private transient char[] toStringCache;//被transient修饰,表示这个字段不被序列化
StringBuffer是被final修饰的,表示不能被其它类继承,;继承了AbstractStringBuilder抽象类,实现了Serializable、CharSequence接口 StringBuffer中的方法被public修饰的都使用了synchronized,保证线程安全。所以StringBuffer是线程安全的类。

 

1 /** 2      * Constructs a string buffer with no characters in it and an 3      * initial capacity of 16 characters. 4      */ 5     public StringBuffer() { 6         super(16); 7     } 8  9     /**10      * Constructs a string buffer with no characters in it and11      * the specified initial capacity.12      *13      * @param      capacity  the initial capacity.14      * @exception  NegativeArraySizeException  if the {
@code capacity}15 * argument is less than {
@code 0}.16 */17 public StringBuffer(int capacity) {18 super(capacity);19 }20 21 /**22 * Constructs a string buffer initialized to the contents of the23 * specified string. The initial capacity of the string buffer is24 * {
@code 16} plus the length of the string argument.25 *26 * @param str the initial contents of the buffer.27 */28 public StringBuffer(String str) {29 super(str.length() + 16);30 append(str);31 }

 

StringBuffer的容量默认是16,当容量不够的时候,容量会继续增加16,依次类推。

 

转载于:https://www.cnblogs.com/lixianyuan-org/p/10474759.html

你可能感兴趣的文章
从超级玛丽说起,谈谈如何为机器赋予好奇心
查看>>
如何让用户只能访问特定的数据库(MSSQL)
查看>>
谈谈WCF中的Data Contract(4):WCF Data Contract Versioning
查看>>
多target设置实战,自己也这么搞过,这篇写的蛮细的,mark一下吧。
查看>>
谁在人肉搜索?——网络人肉搜索主体的Logistic回归模型分析
查看>>
Kylin介绍
查看>>
黑客来势汹汹,受害者能以牙还牙“黑回去”吗
查看>>
大数据还能这么用:看穿式监管 精准锁定异动账户
查看>>
花非花,物非物,AI岂是池中物(人工智能篇)
查看>>
volatile的用法
查看>>
用shell脚本挂载linux主机拷贝相应文件copy.sh
查看>>
高科技行业数字化转型:颠覆你对未来的想象
查看>>
“超融合对战法”,带你杀出一条血路
查看>>
linux 文本处理
查看>>
如何使用Docker部署一个Go Web应用程序
查看>>
开源商业战国时代 红帽如何掘金?
查看>>
应否定互联网金融“HTTPS=安全”观念
查看>>
SamSam勒索软件攻击不断增长,勒索赎金也在不断提高
查看>>
CODE大全
查看>>
穿越2027看“315”消费产品信息安全质量报告
查看>>