buffertest2.java

来自「180个针对Java初学者的简单实例,包含了180個適合與初學者的源碼實例」· Java 代码 · 共 26 行

JAVA
26
字号
class BufferTest2 {
	public static void main(String[] args) {
		// 自动产生
		StringBuffer buffer= new StringBuffer("How are you?");
		
		//display the information of capacity.
		System.out.println("字符串容量是: "+buffer.capacity()+"。\n");
		
		//display the information of length.
		System.out.println("字符串的长度是"+buffer.length()+".\n");
		
		//display the usage of setLength() method.
		buffer.setLength(100000);
		System.out.println("用过方法 setLength(1000) 后");
		System.out.println("此时字符串的长度是: "+buffer.length()+"。");
		buffer.setLength(4);
		System.out.println("用过方法 setLength(4) 后");
		System.out.println("此时长度是: "+ buffer.length()+"。");
		
		//display the usage of charAt() method.
		System.out.println("\n方法 charAt() 的使用。");
		System.out.println("使用了 charAt(2):"+buffer.charAt(2)+" 。");
	}

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?