Android:是否有迭代 SparseArray 的习惯用法
我使用唯一的 int id 列表来对照用户名列表作为快速查找表,并决定使用稀疏数组,但我希望能够不时打印以记录整个列表以进行调试。
SparseArray 不可迭代,并且与 util.Map 接口不太相似
I'm using a list of unique int ids against a list of user names as a fast lookup table and decided to use the sparseArray but I would like to be able print to log the entire list from time to time for debugging purposes.
The SparseArray is not iterable and isn't much like the util.Map interface
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
老鼠是正确的,代码看起来像这样;
Mice was correct, code would look something like this;
使用 SparseArray.size() 获取总大小。
使用 SparseArray.keyAt 和 valueAt 获取给定索引中的键/值。
Use SparseArray.size() to get total size.
Use SparseArray.keyAt and valueAt to get key/value in given index.
以下是如何显示调试跟踪的 SparseArray 内容。
Here's how to display a SparseArray content for debug traces.