Frenkel Smeijers wrote:. . . is the order of the output of the toString()-method of a HashMap of Integers to Integers guaranteed?

No, as Jeanne has already sad.

A HashMap defaults to load factor=75% and initial size=0x10. It contains an array of buckets accessed

*via* the hashCode like this:

` bucketsArray[h & c − 1]`, where

` c `is the capacity (length of array) and

` h `the hash code after rehashing. Rehashing won't alter small numbers like 1 2 3. The hash code of an

` Integer `is equal to its

` int `value. So the pair with key

` 3 `sorts to

` bucketsArray[3]`. There won't be any collisions for three numbers in sequence, nor further rehashing until the size passes

` 16 × (75%)`, so in this unusual situation, it is possible to predict the order of traversal of the Map.