How can I sort android.util.SparseArray?
E.g. I have SparseArray with:
1 - 2.33
5 - 1.5
Result:
5 - 1.5
1 - 2.33
Thanks!!!
-- EDITED
I've used the Map. Thanks for help.
It is not clear if you requested a key or value sorted order ...
so just a note:
A binary search only works on sorted data and SparseArray uses a binary search for its sorted (!) keys array according to the source. So the keys ARE already sorted and won't accept a different order like the order from the values.
One small amendment to @Karussell's spot-on answer is that also the documentation itself of the valueAt()
method suggests a sorted order (on keys):
[...]
valueAt(0)
will return the value associated with the smallest key andvalueAt(size()-1)
will return the value associated with the largest key.
A similar description is given for the keyAt()
method.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With