我想你想在你的集合中有重複的元素,你不能在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