I was curious if I could get help coming up with some easily understandable or even real life applications of the more common Java data structures from the Collections interface. I also added a HashMap example as well. Here is what I have so far:
COLLECTIONS
Simple Array: you want store your unchanging class roster of 300 students for the semester in a list. You can access any of their names by just getting the index.
ArrayList: You want to store your class roster of 300 students next semester. But this time some new students may join in the middle of the semester and some may leave, so you will need to add or remove them in the list accordingly.
Sets: You have a music playlist that you can shuffle through, but you can't add the same song twice!
Queues: There are 20 Amazon Prime Orders. The first order that was placed is the first one that is going to get shipped (FIFO)
Stack: Each of your edits in your Word Doc are saved in a stack. Clicking "undo" will take the last edit made and replace what you wrote. (LIFO)
- also supports recursion
LinkedList: You want to check your browser history and find a webpage you went to a week ago. You can do this by tracking the webpages you visited before and after (doubly linked) the one you're looking for.
MAPS
HashMaps: You want to have a key-value pair mapping of a country and it's corresponding phone number country code. If you forget the country code, you can call the key "Nigeria", and retrieve the value 234.
The Maps interface has a lot of implementations, but I could only think of a HashMap example.
I took a look at this post, but some of the examples didn't point to an actual application or easy to grasp example: Examples of Data Structures in real life
Any Suggestions?
CodePudding user response:
