JavaSE8基础 StringBuffer append 向缓冲区中变量的末尾追加字符串与缓冲区容量的自动扩充

os :windows7 x64
    jdk:jdk-8u131-windows-x64
    ide:Eclipse Oxygen Release (4.7.0)
    
    
code:

package jizuiku1;

public class Demo000 {
	public static void main(String[] args) {
		StringBuffer sb = new StringBuffer();
		System.out.println("缓冲容的容量是:"+sb.capacity());
		System.out.println("字符串的长度是:"+sb.length());

		System.out.println("----------------");

		sb.append("0123456789ABCDEF");//追加一个 长度为16的字符串
		System.out.println("缓冲容的容量是:"+sb.capacity());
		System.out.println("字符串的长度是:"+sb.length());

		System.out.println("----------------");

		sb.append("0");//追加一个 长度为1的字符串,缓冲区存不下了,那么?
		System.out.println("缓冲容的容量是:"+sb.capacity());//自动扩充
		System.out.println("字符串的长度是:"+sb.length());
	}
}

result:



Java优秀,值得学习。
学习资源:API手册+Java源码+清净的心地。

时间: 2024-07-29 10:05:08

JavaSE8基础 StringBuffer append 向缓冲区中变量的末尾追加字符串与缓冲区容量的自动扩充的相关文章

JavaSE8基础 StringBuffer 将一个char字符重复指定次数后输出

os :windows7 x64    jdk:jdk-8u131-windows-x64    ide:Eclipse Oxygen Release (4.7.0) code: package jizuiku0; /* * @version V17.09 */ public class repeatCharDemo { public static void main(String[] args) { // 字符 0 重复输出3次 System.out.println(repeatChar('0

JavaSE8基础 StringBuffer与String变量在追加字符串后,引用变量的地址发生改变

os :windows7 x64    jdk:jdk-8u131-windows-x64    ide:Eclipse Oxygen Release (4.7.0)        code: package jizuiku0; public class Demo11 { public static void main(String[] args) { String str1 = "cnblog"; String str2 = str1 + "jizuiku"; S

JavaSE8基础 StringBuffer delete trimToSize 清空字符串缓冲区与整理缓冲区的空间

os :windows7 x64    jdk:jdk-8u131-windows-x64    ide:Eclipse Oxygen Release (4.7.0)        code: package jizuiku1; public class Demo100 { public static void main(String[] args) { StringBuffer sb = new StringBuffer(); sb.append("cnblog"); System.

JavaSE8基础 在构造代码块中给final类型的成员变量赋值

os :windows7 x64    jdk:jdk-8u131-windows-x64    ide:Eclipse Oxygen Release (4.7.0)        代码: /* * final 修饰值类型的成员变量. */ class Demo { final int num; { num = 1;//在构造代码块中给final类型变量赋值 //num = 2; 但是 不能重复赋值.比如,在num=1后面加上num=2,就会报错! } public static void ma

JavaSE8基础 当父类与子类中的成员变量重名了,使用super.名字 来访问父类的成员变量

os :windows7 x64    jdk:jdk-8u131-windows-x64    ide:Eclipse Oxygen Release (4.7.0)        代码: /* * 当父类与子类中的成员变量重名了,使用super.名字 来访问父类的成员变量 */ //基类 class Person { public int num = 1; } //子类 class Javaer extends Person { //子类中的成员变量与父类重名了 public int num

JavaSE8基础 StringBuffer substring 将变量分割返回String,其本身不变

os :windows7 x64    jdk:jdk-8u131-windows-x64    ide:Eclipse Oxygen Release (4.7.0)        code: package jizuiku1; public class Demo110 { public static void main(String[] args) { StringBuffer sb = new StringBuffer(); sb.append("cnblog"); String

JavaSE8基础 StringBuffer reverse 倒置缓冲区内的字符串

os :windows7 x64    jdk:jdk-8u131-windows-x64    ide:Eclipse Oxygen Release (4.7.0)        code: package jizuiku1; public class Demo101 { public static void main(String[] args) { StringBuffer sb = new StringBuffer(); sb.append("cnblog"); sb.reve

JavaSE8基础 StringBuffer toString 将其转为String对象

os :windows7 x64    jdk:jdk-8u131-windows-x64    ide:Eclipse Oxygen Release (4.7.0)        code: package jizuiku0; public class Demo10 { public static void main(String[] args) { StringBuffer sb = new StringBuffer(); sb.append("cnblog_"); sb.appe

JavaSE8基础 StringBuffer delete 删除指定索引值的一个字符

os :windows7 x64    jdk:jdk-8u131-windows-x64    ide:Eclipse Oxygen Release (4.7.0)        code: package jizuiku1; public class Demo010 { public static void main(String[] args) { StringBuffer sb = new StringBuffer(); sb.append("cnblog_").append(