Saying that there is a list and I add some stuffs in it:
list.add(new Stuff("Test1"))
list.add(new Stuff("Test2"))
list.add(new Stuff("Test3"))
list.add(new Stuff("Test4"))
list.add(new Stuff("Test5"))
and if I put it in the hashmap like this:
private static HashMap<Integer, Report> hashMap = new HashMap<>();
public static void getStuffs(Stuff stuff) {
int hashCode = stuff.hashCode();
if (!hashMap.containsKey(hashCode)) {
hashMap.put(hashCode, stuff);
}
}
And when I print the values that are stored in the hashMap, the expected output is:
Test1
Test2
Test3
Test4
Test5
But it is actually stored in the hashMap in a strange order.
Could someone please tell me how to solve this problem?
I tried