Dictionary or Array

折月煮酒 提交于 2020-01-16 04:42:08

问题


In what situation does it make sense to use a dictionary versus a NSMutableArray?


回答1:


Those are 2 different types of containers. Array is a sequential data storage where you can retrieve elements by index. Dictionary is a hash where you retrieve elements by "names". Both have pros and cons (lookup speed, insertion time, enumeration, etc).

Please read on generic Array vs Hash.




回答2:


Depends on your requirements.

If you need a collection of stuff, any order or even strictly ordered, and you need to iterate over the values, then perhaps an Array suffices.

If your data has a key and a unique key at that (serial number, login name, whatever) then a dictionary is going to give you quick access to the objects by key.



来源:https://stackoverflow.com/questions/5784942/dictionary-or-array

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!