我在使用 arraycopy 从我的数组中删除一个项目时遇到问题。我有两种方法 find (定位要删除的项目的索引)和 delete (删除)。它不会删除任何东西。先感谢您。
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);
}
}