常见对象_StringBuffer的截取功能

package cn.itcast_06;

/*
 * StringBuffer的截取功能:注意:返回值类型不再是StringBuffer本身了
 * 		public String substring(int start):
 * 		public String substring(int start,int end):
 */
public class StringBufferDemo {
	public static void main(String[] args) {
		//创建字符串缓冲区对象
		StringBuffer sb = new StringBuffer();
		
		//添加数据
		sb.append("hello").append("world").append("java");
		System.out.println("sb:"+sb);
		
		//截取功能
		String s = sb.substring(5);
		System.out.println("s:"+s);
		System.out.println("sb:"+sb);
		
		//public String substring(int start,int end):
		//需求:把world截掉
		String ss = sb.substring(5, 10);
		System.out.println("ss:"+ss);//world
		System.out.println("sb:"+sb);
	
	}
}

你可能感兴趣的:(Java,常见对象,String,StringBuffer)