why order is wrong for the output?I thought it is in alphabetical order? https://code.sololearn.com/cVaETg59mVn0/?ref=app
A hash is generated for every element in a hashset. The elements are displayed based on their "hashes" but not in alphabetical order.
Hashes are calculated by some algorithm. It depends on that algorithm whether you get the same order as you would with alphabetical ordering.
they are explicitly saying if you want to keep order to use a LinkedHashSet
Because it's ordered by the objects hash code and not by their value.
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.
so it only works on characters like A,B,C???
when im reading the comments from the hashset lesson in sololearn.why do they say it is in alphabetical order.so they are wrong?