StringBuffer delete()、deleteCharAt()方法

public class DeleteDemo {
	public static void main(String[] args) {
		  
	    StringBuffer buff = new StringBuffer("It's not cool");
	    System.out.println("buffer = " + buff);
	 
	    // deleting character from index 5 to index 9
	    buff.delete(5, 9);
	    System.out.println("After deletion = " + buff);

	    buff = new StringBuffer("abcd");
	    System.out.println("buffer = " + buff);
	    // deleting character at index 2
	    buff.deleteCharAt(2);
	    System.out.println("After deletion = " + buff);
	    
	    buff = new StringBuffer("abcd");
	    System.out.println("buffer = " + buff);
	    // 删除最后一个字符
	    buff.deleteCharAt(buff.length()-1);
	    System.out.println("After deletion = " + buff);
	  }
}

运行程序,结果为
 
  

buffer = It's not cool
After deletion = It's cool
buffer = abcd
After deletion = abd
buffer = abcd
After deletion = abc


你可能感兴趣的:(Android)