JDK源码阅读--StringBuffer
2024-09-06 08:06:29
public final class StringBuffer
extends AbstractStringBuilder
implements java.io.Serializable, CharSequence
/**
* A cache of the last value returned by toString. Cleared
* whenever the StringBuffer is modified.
*/
private transient char[] toStringCache;//被transient修饰,表示这个字段不被序列化
StringBuffer是被final修饰的,表示不能被其它类继承,;继承了AbstractStringBuilder抽象类,实现了Serializable、CharSequence接口 StringBuffer中的方法被public修饰的都使用了synchronized,保证线程安全。所以StringBuffer是线程安全的类。
/**
* Constructs a string buffer with no characters in it and an
* initial capacity of 16 characters.
*/
public StringBuffer() {
super(16);
} /**
* Constructs a string buffer with no characters in it and
* the specified initial capacity.
*
* @param capacity the initial capacity.
* @exception NegativeArraySizeException if the {@code capacity}
* argument is less than {@code 0}.
*/
public StringBuffer(int capacity) {
super(capacity);
} /**
* Constructs a string buffer initialized to the contents of the
* specified string. The initial capacity of the string buffer is
* {@code 16} plus the length of the string argument.
*
* @param str the initial contents of the buffer.
*/
public StringBuffer(String str) {
super(str.length() + 16);
append(str);
}
StringBuffer的容量默认是16,当容量不够的时候,容量会继续增加16,依次类推。
最新文章
- entityframework学习笔记--006-表拆分与实体拆分
- [转载]El Capitan 中 SIP 介绍
- 剑指Offer面试题:12.在O(1)时间删除链表结点
- T-Sql(七)用户权限操作(grant)
- tp5页面输出时,搜索后跳转下一页的处理
- iOS/Android网络消息推送的实现两种方法
- git 回滚
- 【uTenux实验】写在开始实验之前
- php 用post请求调用接口api
- 从jdbc到mybatis
- std::forward_list
- J Query库
- MySQL连接数实时查看
- ASP.NET Core轻松入门之Configure中IHostingEnvironment和IApplicationLifetime的使用
- glusterfs 4.0.1 rpc 分析笔记1
- 3D GIS 应用开发 —— 基于 Mapbox GL 的实践总结
- 编写函数,接受一个string,返回一个bool值,指出string是否有5个或者更多字符,使用此函数打印出长度大于等于5的元素
- Java类集 List, Set, Map, Stack, Properties基本使用
- Oracle如何解决日期格式“01-3月 -18”的显示问题(3种处理方式)
- Spark 编程模型(下)