我想你想在你的集合中有重复的元素,你不能在Set
中有重复的元素,就像在数学中定义set一样。 Oracle的Java说为Set
集合:
A collection that contains no duplicate elements.
More formally, sets contain no pair of elements e1 and e2
such that e1.equals(e2),
and at most one null element. As implied by its name,
this interface models the mathematical set abstraction.
但这种限制不List
收集存在,Oracle的Java说的 '列表',集合:
Unlike sets, lists typically allow duplicate elements.
More formally, lists typically allow pairs of elements e1 and e2
such that e1.equals(e2), and they typically allow multiple null elements
if they allow null elements at all.
It is not inconceivable that someone might wish to implement
a list that prohibits duplicates,
by throwing runtime exceptions when the user attempts to insert them,
but we expect this usage to be rare.
所以你不能有重复的elemet在您的set
实例中。
更多信息,请参阅本网站的以下问题:
块引用
来源
2012-03-11 07:23:11
MJM
看起来像作业。是吗? – 2012-03-11 07:16:52
你的意思是'int n = intList.get(0).intValue()'? – 2012-03-11 07:17:15
我认出你的风格@ user1261935(又名user1254044)。伙计们,这家伙是连续的“懒惰问题”提问者。不要鼓励他。 – 2012-03-11 07:35:42