How to iterate through SparseArray?

后端 未结 10 1747
野的像风
野的像风 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:40

    If you don't care about the keys, then valueAt(int) can be used to while iterating through the sparse array to access the values directly.

    for(int i = 0, nsize = sparseArray.size(); i < nsize; i++) {
        Object obj = sparseArray.valueAt(i);
    }
    

提交回复
热议问题