Java,设置特定的HashSet树集

Java,设置特定的HashSet树集,java,hash,tree,set,Java,Hash,Tree,Set,正在尝试将.txt文件中的单词保存到集合中。以前从未使用过电视机 Set<Word> set = new HashSet<Word>(); Set Set=newhashset(); 在哈希集中保存时,我将大小设置为241。 如果我将上面的更改为 Set<Word> set = new TreeSet<Word>(); Set Set=new TreeSet(); 代码中没有其他内容,我的尺寸是231。在不同的集合中是否存在某种自然原因?您

正在尝试将.txt文件中的单词保存到集合中。以前从未使用过电视机

Set<Word> set = new HashSet<Word>();
Set Set=newhashset();
在哈希集中保存时,我将大小设置为241。 如果我将上面的更改为

Set<Word> set = new TreeSet<Word>();
Set Set=new TreeSet();

代码中没有其他内容,我的尺寸是231。在不同的集合中是否存在某种自然原因?

您可能没有使
具有可比性。compareTo
对象一致。equals/hashCode
。或
hashCode
等于
不一致。可能没有实际覆盖
hashCode
-使用
@Override
来确保。

您可能没有使
具有可比性。compareTo
对象一致。等于/hashCode
。或
hashCode
等于
不一致。可能没有实际覆盖
hashCode
-请使用
@Override
确保。

我们可以查看您的
Word
类吗?它是否覆盖了
hashCode
equals
方法?是的,它是equals方法,thx!我们能看看你的
Word
课吗?它是否覆盖了
hashCode
equals
方法?是的,它是equals方法,thx!是的,这是我对equals方法的实现,thx alot!=)是的,这是我对equals方法的实现,thx alot!=)