Which_Data_Structure_to_Use

Which data structure to use?

Sourece Of Data

  1. From the program itself
  2. From the UI
  3. From external sources

For Simple List: Arrays or Sets

Arrays

  • Use when you need ordered list of values (might contain duplicates)
  • Use when you need to manipulate data

Sets

  • Use when you need to work with unique values
  • Use when high-performance is really important
  • Use to remove duplicates from arrays

For Key/Value Pairs: Objects or Maps

Objects

  • Features
    • More “traditional” key/value store(“abused” objects)
    • Easier to write and access values with . and [ ]
  • Use when
    • you need to include functions(methods)
    • working with JSON(can convert to map)

Maps

  • Features
    • Better performance
    • Keys can have any data type
    • Easy to iterate
    • Easy to compute size
  • Use when
    • you simply need to map key to values
    • you need keys that are not strings

本站由 @Eureka 使用 Stellar 主题创建。
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议,转载请注明出处。