I need to have a resultset converted into a Map of Maps. The reason why I'm not using a List of Maps is because I don't want to iterate through the entire List to get a specific row.
The problem I am facing now is that the HashMap's entries aren't ordered anymore if the index is greater than 16.
Now I tried the following for a simple test:
public static void main(String[] args) {
Map<Integer, String> map = new HashMap<Integer, String>();
//creating 20 rows from 1 to 20
for (int i = 1; i <= 20; i++){
map.put(i, "ROW "+i);
}
//returning all the rows the map contains. Look at position 16.
for(int key : map.keySet()){
System.out.println(key);
}
}
And the output is the following (look at position 16 to 20. They are totally unordered):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 17 16 19 18 20
I would really appreciate it, if someone can explain why that happens.
And by the way:
i cant use something like this:
for (int i = 0; i < map.size; i++){
map.get(i) //...and so on
}
because I don't know if the index exists. It may be that that the index from 200 to 800 doesnt exist. So it would be better only to iterate through exisiting entries of the map.