0
Hashset question
why order is wrong for the output?I thought it is in alphabetical order? https://code.sololearn.com/cVaETg59mVn0/?ref=app
7 odpowiedzi
+ 12
A hash is generated for every element in a hashset. The elements are displayed based on their "hashes" but not in alphabetical order.
+ 2
Hashes are calculated by some algorithm. It depends on that algorithm whether you get the same order as you would with alphabetical ordering.
+ 2
they are explicitly saying if you want to keep order to use a LinkedHashSet
0
Because it's ordered by the objects hash code and not by their value.
0
as others have pointed out, hashsets are sorted after the objects hash. You can use an Arraylist and Collections.sort if you need it to be sorted in other ways.
0
so it only works on characters like A,B,C???
0
when im reading the comments from the hashset lesson in sololearn.why do they say it is in alphabetical order.so they are wrong?