1

arraycopy を使用して配列から項目を削除する際に問題が発生しています。find (削除するアイテムのインデックスを見つける) と delete (削除を行う) の 2 つのメソッドがあります。何も削除しません。前もって感謝します。

 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);
     }      
}
4

2 に答える 2

0

sa をディープ コピーして tempArray の新しいオブジェクトを作成します。

于 2013-04-18T05:23:40.103 に答える