字符串是什么意思 字符怎么输入( 六 )


package character;public class MyStringBuffer implements IStringBuffer{}9.10 MyStringBuffer
具体文字说明:how2j.cn/k/number-st…
package digit;public class MyStringBuffer implements IStringBuffer{int capacity = 19;int length = 0;char []value;// 无参构造方法public MyStringBuffer(){value = http://www.fzline.cn//sh/new char[capacity];}// 带参数构造方法public MyStringBuffer(String str){this();if (null == str)return;if(capacity < str.length()){capacity = value.length * 2;value = new char[capacity];}if (capacity >= str.length()){System.arraycopy(str.toCharArray(),0,value,0,str.length());}length = str.length();}//追加字符串@Overridepublic void append(String str){insert(length,str);}//追加字符@Overridepublic void append(char c){append(String.valueOf(c));}//指定位置插入字符@Overridepublic void insert(int pos,char b){insert(pos,String.valueOf(b));}//指定位置插入字符串@Overridepublic void insert(int pos,String b){//边界条件判断if (pos < 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 sb = new MyStringBuffer("there light");System.out.println(sb);sb.insert(0, "let ");System.out.println(sb);sb.insert(10, "be ");System.out.println(sb);sb.insert(0, "God Say:");System.out.println(sb);sb.append("!");System.out.println(sb);sb.append('?');System.out.println(sb);sb.reverse();System.out.println(sb);sb.reverse();System.out.println(sb);sb.delete(0,4);System.out.println(sb);sb.delete(4);System.out.println(sb);}}

推荐阅读