stringbuffer1.java
来自「java程序设计 清华出版社 孙燮华老师编写的程序源代码」· Java 代码 · 共 22 行
JAVA
22 行
//StringBuffer1.java
public class StringBuffer1{
public static void main(String[] args) {
StringBuffer buf1=new StringBuffer(); //创建空字符串变量
StringBuffer buf2=new StringBuffer(10); //创建空字符串变量,初始长度为10个字符
StringBuffer buf3=new StringBuffer("hello");//用指定串"hello"创建字符串变量
//使用StringBuffer的toString方法将三个StringBuffer对象转换成String对象输出
System.out.print("buf1 = " + buf1.toString()+" , ");
System.out.print("buf2 = " + buf2.toString()+" , ");
System.out.print("buf3 = " + buf3.toString()+"\n");
//返回当前字符串长度
System.out.print("buf1.length() = "+buf1.length()+", ");
System.out.print("buf2.length() = "+buf2.length()+", ");
System.out.print("buf2.length() = "+buf3.length()+"\n");
//返回当前缓冲区长度
System.out.print("buf1.capacity() = "+ buf1.capacity()+", ");
System.out.print("buf2.capacity() = "+ buf2.capacity()+", ");
System.out.print("buf3.capacity() = "+ buf3.capacity()+"\n");
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?