Java's StringBuilder and StringBuffer

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/weixin_45778981/article/details/102754736

Java's StringBuilder and StringBuffer

(1)
high StringBuilder efficiency, safety, low
low StringBuffer efficiency, safety
(2)
the parent AbstractStringBufferBuilder both of which are a common
both in the use of almost interoperability

public class TestStringBuilder {
	   public static void main(String[] args) {
		StringBuilder h=new StringBuilder();
		//字符串的追加
		h.append("holle ");
		h.append('你');
		h.append(true);	
		h.append(520);
		System.out.println(h.toString());
		h.delete(3,5);//含头不含尾的删除
		System.out.println(h);
		h.deleteCharAt(1);//删除指定位置
		System.out.println(h);
		h.insert(2,'想');
		System.out.println(h);
		System.out.println(h.indexOf("t")+"\t"+h.indexOf("m"));//查找
		h.capacity();//容量 扩容初始长度x2+2	当容量不够时会自动扩容
	}
}

Guess you like

Origin blog.csdn.net/weixin_45778981/article/details/102754736