sp; return (minCapacity > MAX_ARRAY_SIZE) ? Integer.MAX_VALUE : MAX_ARRAY_SIZE; } /** * 未实现 */ public boolean add(E e) { throw new UnsupportedOperationException(); } /** * 功能:移除指定元素 * (1)如果参数为null,则找到第一个值为null的元素,并将其删除,返回true,如果不存在null的元素,返回false。 * (2)如果参数不为null,则根据equals方法找到第一个与参数相等的元素,并将其删除,返回true,如果找不到,返回false。 */ public boolean remove(Object o) { Iterator<E> it = iterator(); if (o==null) { while (it.hasNext()) { if (it.next()==null) { it.remove(); return true; } } } else { while (it.hasNext()) { if (o.equals(it.next())) { it.remove(); return true; } } } return false; } /** * 遍历参数集合,依次判断参数集合中的元素是否在当前集合中, * 只要有一个不存在,则返回false * 如果参数集合中所有的元素都在当前集合中,则返回true */ public boolean containsAll(Collection<?> c) { for (Object e : c) if (!contains(e)) return false; return true; } /** * 遍历参数集合,依次将参数集合中的元素添加当前集合中 */ public boolean addAll(Collection<? extends E> c) { boolean modified = false; for (E e : c) if (add(e)) modified = true; return modified; } /** * 功能:移除参数集合的元素 * (1)获取当前集合的迭代器进行遍历 * (2)如果当前集合中的元素包含在参数集合中,则删除当前集合中的元素 * 注:只要参数集合中有任何一个元素在当前元素中,则返回true,表示当前集合有发送变化,否则返回false。 */ public boolean removeAll(Collection<?> c) { boolean modified = false; Iterator<?> it = iterator(); while (it.hasNext()) { if (c.contains(it.next())) { it.remove(); modified = true; } } return modified; } /*** * 功能 |