<PLEASE USE THE FOLLOWING TEMPLATE TO HELP YOU CREATE A GREAT POST!>
<Below this line, add a link to the EXACT exercise that you are stuck at.>
<In what way does your code behave incorrectly? Include ALL error messages.>
In the restaurant menu the contents are entered in the order Turkey Burger; Naan Pizza and then Cranberry Kale Salad.
However, it prints in the order Turkey Burger, Cranberry Kale Salad and Naan Pizza.
I’m just curious as to why this is.
<img src="//codecademy-discourse.s3.amazonaws.com/original/5X/0/e/8/8/0e8896be4eb3f8a25c312854ccb35f8dcce87be6.PNG" width="690" height="439">
If it is like other languages, associative arrays don’t remember the order in which items are inserted. They are unordered and may be iterated in any order.
But that can’t be true! I learned a few episodes earlier that for an array you can add items or even add an item to a specific placement. Is it that HashMaps don’t have a way to record order?
Not without help they don’t.
HashMap does not guarantee the order, it was designed that way so that it get better performance for its basic operations (
put). If you wanted ordered HashMaps you should look into
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.