< 0)return;if(pos > length)return;if (null == b)return;//扩容while(length + b.length() > capacity){capacity = (int)((length + b.length())*2);char []new_value = new char[capacity];System.arraycopy(value,0,new_value,0,length);value = new_value;}char []cs = b.toCharArray();//先把已经存在的数据往后移System.arraycopy(value,pos,value,pos+cs.length,length-pos);//把要插入的数据插入到指定位置System.arraycopy(cs, 0, value, pos, cs.length);length = length+cs.length;}//从开始位置删除剩下的@Overridepublic void delete(int start){delete(start,length);}//从开始位置删除结束位置-1@Overridepublic void delete(int start,int end){//边界条件判断if(start<0) return;if(start>length) return;if(end<0) return;if(end>length) return;if(start>=end) return;System.arraycopy(value, end, value, start, length- end);length-=end-start;}//反转@Overridepublic void reverse(){for (int i = 0; i < length / 2; i++) {char temp = value[i];value[i] = value[length - i - 1];value[length - i - 1] = temp;}}//返回长度@Overridepublic int length(){return length;}public String toString() {char[] realValue = new char[length];System.arraycopy(value, 0, realValue, 0, length);return new String(realValue);}public static void main(String[] args) {MyStringBuffer***= new MyStringBuffer("there light");System.out.println( *** );*** .insert(0, "let ");System.out.println( *** );*** .insert(10, "be ");System.out.println( *** );*** .insert(0, "God Say:");System.out.println( *** );*** .append("!");System.out.println( *** );*** .append('?');System.out.println( *** );*** .reverse();System.out.println( *** );*** .reverse();System.out.println( *** );*** .delete(0,4);System.out.println( *** );*** .delete(4);System.out.println( *** );}}

文章插图
【wa字符串是什么意思字符串是什么意思】
推荐阅读
- 錾刻 錾
- 瓦肆是什么意思 瓦斯是什么
- Columbia是什么牌子的刀 columbia是什么牌子
- 豆豉酱,豆瓣
- 天然气锅炉显示e9是什么意思 天然气显示e9是什么意思
- cover什么意思,cover
- 运营商锁
- 畜的动物是什么 牲畜是指哪些动物?
- 东京奥运会首金是什么 东京奥运会首金是哪个国家拿走了??
- 淀粉是什么原料做成的 淀粉是什么做的?