Which_Data_Structure_to_Use
Which data structure to use?
Sourece Of Data
- From the program itself
- From the UI
- 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