简体   繁体   中英

Which is a more efficient data structure for song data (Title, artist, tempo, genre) from a CSV file? HashMap or ArrayList?

I am trying to make a simple music database that will generate a playlist based off of song tempo and genre. However, I am stuck trying to decide the best data structure to use to parse my CSV file to.

If I use an ArrayList, I would create a Song class, and the ArrayList would be my music database. The song class would have getters and setters for Title Artist Tempo and Genre. I would get my resultant playlist by using conditionals to whittle down the contents of our ArrayList (if tempo isn't at least a certain number, etc)

If I use a HashMap, I would set the keys to a pair , and values to pair (So it would be HashMap<,>).

What is the most efficient way to organize this information?

It depends on how much data this database will contain and what fields will be searched. I think the most general way is a List for the database itself, where items are appended and removed (maybe mark deleted) by the implicit ID that may be the index in the list.

Then, for performance reasons you'll likely need to keep some form of indices. The data structure used in real databases is the tree, but you may also use an ordered list for each field and perform a binary search to keep it simple.

Also, consider that for Java there are many databases (Derby, H2) that are really small, lightweight, can run in-process and have an SQL interface.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM