How to preserve insertion order in HashMap? [duplicate]

LinkedHashMap is precisely what you’re looking for.

It is exactly like HashMap, except that when you iterate over it, it presents the items in the insertion order.

Leave a Comment