You can use a LinkedHashMap if you want a HashMap whose iteration order does not change.
Moreover you should always use it if you iterate through the collection. Iterating over HashMap’s entrySet or keySet is much slower than over LinkedHashMap’s.
More Related Contents:
- Remove Elements from a HashSet while Iterating [duplicate]
- Iterate through a HashMap [duplicate]
- Why there is no ConcurrentHashSet against ConcurrentHashMap
- Changing HashMap keys during iteration
- Difference between HashSet and HashMap?
- Why does HashSet implementation in Sun Java use HashMap as its backing?
- Adding iterations together in Java
- Java Hashmap: How to get key from value?
- Concurrent Modification Exception : adding to an ArrayList
- Sorting HashMap by values [duplicate]
- Is a Java hashmap search really O(1)?
- How to calculate the intersection of two sets? [duplicate]
- Is the order guaranteed for the return of keys and values from a LinkedHashMap object?
- How to update a value, given a key in a hashmap?
- How can I combine two HashMap objects containing the same types?
- Using a byte array as Map key
- Does Java have a HashMap with reverse lookup?
- Is it safe to get values from a java.util.HashMap from multiple threads (no modification)?
- creating Hashmap from a JSON String
- Using an instance of an object as a key in hashmap, and then access it with exactly new object? [duplicate]
- Iterating through a LinkedHashMap in reverse order
- ConcurrentHashMap and Hashtable in Java [duplicate]
- Limiting the max size of a HashMap in Java
- Mutable objects and hashCode
- How do I create some variable type alias in Java
- Java HashSet with a custom equality criteria? [duplicate]
- Theoretical limit for number of keys (objects) that can be stored in a HashMap?
- JSTL iterate over list of objects
- what is the best way to get a sub HashMap based on a list of Keys?
- Is Java HashMap.clear() and remove() memory effective?