I do not think that any of the existing answers is consistent with exactly what you are asking. Undoubtedly, a HashMap with certain content may not be sorted the same way as another, with equal content or another virtual machine call, or work in different versions of JDK, etc. But you just ask if this exact instance, if not modified, will go the same way as it does itself.
This is a good example of a de facto specification. It is true that there is no specification in the letter, that it will be so. However, each individual JDK collection behaves in this way (provided that in the case of an access-related LinkedHashMap that you repeat each time). And it is difficult to imagine the implementation of a collection that would not have this property. I implemented and looked through many collections, and only once did I count a collection that would be repeated differently each time; it was an extremely strange case, and I ended up choosing the whole idea, because the repetition in different ways each time was just too strange (that is, a violation of the de facto specification that I mentioned).
So I say go from there. This is not a complete recommendation, depending on any old unspecified behavior you want. But in this case, it just does not hurt you.
source share