I have a HashMap defined as such:
public Map<Integer, String> staticBlockPositions = new HashMap<Integer, String>();
I am iterating over the map by getting each key, like this:
for (Integer key : blockPositions.keySet()) {
System.out.println(key);
}
My question is, can I rely on the value of key
to always be in ascending order. So if my HashMap looks something like this:
{
4: "abc123",
1: "def456",
11: "qwe789",
10: "iop019"
}
(I know this is JSON format, this is just so you get an idea of the data set).
Will my loop always output
1
4
10
11
regardless of the order of my data?
Important to note, the order in which the keys are add is completely random, and I cannot control what key is added when.
This is for a Tetris style game, so getting the keys in ascending order is a must.