• Post Reply Bookmark Topic Watch Topic
  • New Topic

HashMap - unsorted, unordered  RSS feed

 
Dana Ucaed
Ranch Hand
Posts: 354
6
Netbeans IDE Oracle Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I read that HashMap are unsorted and unordered.

Means that there isn't no way implicit (conform with documentation) to sort the elements from HashMap?

If you want to display the HashMap I will obtain random values, means system.out.println(hashmap) will not display the same values in the same order.



Thanks in advance!
 
Henry Wong
author
Sheriff
Posts: 23282
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dana Ucaed wrote:
If you want to display the HashMap I will obtain random values, means system.out.println(hashmap) will not display the same values in the same order.


This is *not* true. Unordered does not mean random order. Unordered also does not mean a different order per application execution.

Unordered merely means that no ordering were done, as part of the HashMap's design, and implementation. You may be able to determine a predicable order based on hash codes, or how the elements were added, or for your machine, OS, JVM, etc... but ... any order you find will be coincidental. Unordered means that there is no documented/guaranteed order -- it does not guarantee an order that is changing and random.

Henry
 
Dana Ucaed
Ranch Hand
Posts: 354
6
Netbeans IDE Oracle Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Unordered merely means that no ordering were done, as part of the HashMap's design, and implementation. You may be able to determine a predicable order based on hash codes, or how the elements were added, or for your machine, OS, JVM, etc... but ... any order you find will be coincidental. Unordered means that there is no documented/guaranteed order -- it does not guarantee an order that is changing and random.


This is essential.
Thanks Henry.

It was unclear for me what is means unordered.


 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!