How is this HashSet producing sorted output?

前端 未结 5 1667
旧巷少年郎
旧巷少年郎 2020-11-30 12:45

The following code produces the out put [1,2]even though hashset is not sorted.

Set set = new HashSet();
set.add(new Integer(2));
set.add(new In         


        
5条回答
  •  遥遥无期
    2020-11-30 13:44

    Got a conclusion after several trial and error. This is purely based on hashing order. And that is why we call HASH set. Hashing is based on length of the input. Try 4 single digit numbers with 4 double digit numbers. You will get result.

提交回复
热议问题