我在使用arraycopy从阵列中删除项目时遇到问题。 我有两种方法找到(找到要删除的项目的索引)和 删除(删除)。 它不会删除任何东西。先谢谢你。使用arraycopy从阵列中删除项目
public void find(Comparable value2){
Scanner sc = new Scanner(System.in);
Comparable value = value2;
if (empty() == true){
System.out.println("The array is empty");
}
else{
int bsValue = Arrays.binarySearch(sa,value);
System.out.println("The index is: " + bsValue);
delete(bsValue);
}
}
public void delete(int bs){
int location = bs;
Comparable[] tempArray = new Comparable[sa.length -1];
System.arraycopy(sa, 0, tempArray, 0, location);
if (sa.length != location){
System.arraycopy(sa, location +1 , tempArray, location, sa.length - location - 1);
}
}
小记,你不将做工作”不得不写'(empty()== true)'。你可以写'(空())'(更好的方法)。 – Maroun 2013-04-18 05:20:08