Just curious about the print order in this e.g


#1



12/13


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">


#2

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.


#3

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?


#4

Not without help they don't.


#5

HashMap does not guarantee the order, it was designed that way so that it get better performance for its basic operations (get and put). If you wanted ordered HashMaps you should look into LinkedHashMap


#6

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.