Ensures that this collection contains the specified element (optional
operation). Returns <tt>true</tt> if this collection changed as a
result of the call. (Returns <tt>false</tt> if this collection does
not permit duplicates and already contains the specified element.)<p>
Collections that support this operation may place limitations on what
elements may be added to this collection. In particular, some
collections will refuse to add <tt>null</tt> elements, and others will
impose restrictions on the type of elements that may be added.
Collection classes should clearly specify in their documentation any
restrictions on what elements may be added.<p>
If a collection refuses to add a particular element for any reason
other than that it already contains the element, it <i>must</i> throw
an exception (rather than returning <tt>false</tt>). This preserves
the invariant that a collection always contains the specified element
after this call returns.
确保此 collection 包含指定的元素(可选操作)。如果此 collection 随调用的结果而发生改变,则返回 true。(如果此 collection 不允许有重复元素,并且已经包含了指定的元素,则返回 false。)
支持此操作的 collection 可以限制哪些元素能添加到此 collection 中来。需要特别指出的是,一些 collection 拒绝添加 null 元素,其他一些 collection 将对可以添加的元素类型强加限制。Collection 类应该在其文档中清楚地指定能添加哪些元素方面的所有限制。
如果 collection 由于某些原因(已经包含该元素的原因除外)拒绝添加特定的元素,那么它必须 抛出一个异常(而不是返回 false)。这确保了在此调用返回后,collection 总是包含指定的元素。
------解决方案--------------------