串
由零个或者多个字符的顺序排列所组成的数据结构,其基本构成元素是单个字符。(char)。
空串:不包含任何字符,长度为0
空白串:是由一个或多个空白字符所组成
字符串的存储结构包括顺序存储结构和链式存储结构
下面我们主要探究串的顺序存储结构:
插入操作
public void insert(int pos,String str){
if (pos<0||pos>curlen) {
throw new StringIndexOutOfBoundsException("数组越界");
}
int len = str.length();
int newcount = len+curlen;
//开辟空间
if (newcount>strvalue.length) {
allocate(newcount);
}
//移动
for(int i=curlen-1;i>=pos;i--){
strvalue[i+len] = strvalue[i];
}
//插入
for (int i = 0; i < len; i++) {
strvalue[pos+i] = str.charAt(i);
}
curlen = newcount;
}
删除操作
public void delete(int pos,int end){
if (pos>end||pos<0||end>curlen) {
throw