标签:构造 字符 一个 oid static strong 构建 内容 ati
1、StringBuffer类概述
2、StringBuuffer和String的区别?
前者长度和内容可变,后者不可变
3、构造方法
public class StringBufferDemo { public static void main(String[] args) { //public StringBuffer(); StringBuffer buffer1 = new StringBuffer(); System.out.println("buffer1:"+buffer1); System.out.println("buffer1.capacity:"+buffer1.capacity()); System.out.println("buffer1.length:"+buffer1.length()); System.out.println("---------------------------------"); } }
运行结果:
buffer1: buffer1.capacity:16 buffer1.length:0 //没有加入字符
为什么buffer1.capacity为16?
/** * Constructs a string buffer with no characters in it and an * initial capacity of 16 characters. */
public StringBuffer() { super(16); }
标签:构造 字符 一个 oid static strong 构建 内容 ati
原文地址:https://www.cnblogs.com/hanlu0516/p/10919047.html