标签:删除数组元素 算法 面试算法 删除数组多个连续元素
本文允许转载,但请标明出处:http://blog.csdn.net/wanghantong/article/details/46730591, 版权所有
<span style="font-size:14px;">char[] value;
int count;
public AbstractStringBuilder delete(int start, int end) {
if (start < 0)
throw new StringIndexOutOfBoundsException(start);
if (end > count)
end = count;
if (start > end)
throw new StringIndexOutOfBoundsException();
int len = end - start;
if (len > 0) {
System.arraycopy(value, start+len, value, start, count-end);
count -= len;
}
return this;
}</span>本文允许转载,但请标明出处:http://blog.csdn.net/wanghantong/article/details/46730591,
版权所有<span style="font-size:14px;">Test System.arraycopy()方法:
String[] array1 = { "1", "2", "3", "4", "5" };
//System.arraycopy(value, start+len, value, start, count-end);
//System.arraycopy(src, srcPos, dest, destPos, length);
System.arraycopy(array1, 4, array1, 3,1);
//从索引为4的元素开始,替换了从起始索引为3的元素,替换长度为1
printArray(array1);//1 2 3 5 5</span>版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:删除数组元素 算法 面试算法 删除数组多个连续元素
原文地址:http://blog.csdn.net/wanghantong/article/details/46730591