HashMap
is not ordered. You don't have any control over what order the items appear in. If you want an ordered map, you can use, for example, TreeMap
.
EDIT: thanks to those that brought this up: TreeMap
will keep items in the natural sorting order (i.e. in your case in alphabetical order). LinkedHashMap
will preserve the order of insertion.