javaandroidsparse-array

SparseArray clone in Android


I am trying to iterate through a SparseArray and delete a few items.

private SparseArray record;

   int size = record.size();
        for (int index = 0; index < size; index++) {
            if (record.valueAt(index) < threshold){
                record.delete(record.keyAt(index));
            }
        }

But if I remove items midway through iteration, the size will change, So I cannot use this. I tried to clone the sparse array beforehand. But eclipse gives me error

The method clone() from the type object is not visible

But both api doc and Source code of SparseArray indicate it is present and public. Also the method clone has an annotation @SuppressWarnings("unchecked")

Does suppressing change the visibility of method?
Anyone has a clue how to solve this or clone the SparseArray?


Solution

  • According to the Android API changes for SDK 14, we find that SparseArray was modified to include a public clone.

    Edit

    In my project, I implemented my own clone code for SB array: Source code here