常用类之StringBuffer

位置

在这里插入图片描述

继承树

在这里插入图片描述

所有实现的接口

在这里插入图片描述

官方解释

任何时候,我们都应该尝试首先阅读英文文档。
A thread-safe, mutable sequence of characters. 一个线程安全的,可改变的字符序列。
A string buffer is like a String, but can be modified.它很像String,但是它是可变的。
At any point in time it contains some particular sequence of characters, but the length and content of the sequence can be changed through certain method calls.在任何时间点,它包含一个可改变的序列,通过方法的调用可以改变。
String buffers are safe for use by multiple threads字符串缓冲区对于多线程使用是安全的。
For example, if z refers to a string buffer object whose current contents are “start”, then the method call z.append(“le”) would cause the string buffer to contain “startle”, whereas z.insert(4, “le”) would alter the string buffer to contain “starlet”.使用append和insert方法可以添加字符串。
Every string buffer has a capacity. As long as the length of the character sequence contained in the string buffer does not exceed the capacity, it is not necessary to allocate a new internal buffer array. If the internal buffer overflows, it is automatically made larger.每个缓冲区有一个特定的容量,当字符串太长时会自动扩展。
Unless otherwise noted, passing a null argument to a constructor or method in this class will cause a NullPointerException to be thrown.除非另有说明,传递空参数会造成空指针异常。

构造函数

在这里插入图片描述

方法(有好多)

StringBuffer都在这里,有需要的自行查看。

小测试

单线程:

public static void main(String[] args) {
		StringBuffer sb=new StringBuffer();
		sb.append(true);
		System.out.println(sb.length());
		sb.append(23.21);
		System.out.println(sb.length());
	}

输出分别为4,和9。true和23.21都变成了字符序列。
其他的应用也很简单,只要你想探索,对未知充满好奇。
多线程:
待续。。。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值