How to iterate through SparseArray?

后端 未结 10 1738
野的像风
野的像风 2020-11-30 18:16

Is there a way to iterate over Java SparseArray (for Android) ? I used sparsearray to easily get values by index. I could not find one.

10条回答
  •  天命终不由人
    2020-11-30 18:52

    The answer is no because SparseArray doesn't provide it. As pst put it, this thing doesn't provide any interfaces.

    You could loop from 0 - size() and skip values that return null, but that is about it.

    As I state in my comment, if you need to iterate use a Map instead of a SparseArray. For example, use a TreeMap which iterates in order by the key.

    TreeMap
    

提交回复
热议问题