Inserts the objects in the specified collection at the specified location in this vector. The objects are inserted in the order in which they are returned from the Collection iterator. The elements with an index equal or higher than location have their index increased by the size of the adde
(int location,
Collection<? extends E> collection)
| 168 | * if {@code location < 0} or {@code location > size()}. |
| 169 | */ |
| 170 | @Override |
| 171 | public synchronized boolean addAll(int location, |
| 172 | Collection<? extends E> collection) { |
| 173 | if (0 <= location && location <= elementCount) { |
| 174 | int size = collection.size(); |
| 175 | if (size == 0) { |
| 176 | return false; |
| 177 | } |
| 178 | int required = size - (elementData.length - elementCount); |
| 179 | if (required > 0) { |
| 180 | growBy(required); |
| 181 | } |
| 182 | int count = elementCount - location; |
| 183 | if (count > 0) { |
| 184 | System.arraycopy(elementData, location, elementData, location |
| 185 | + size, count); |
| 186 | } |
| 187 | Iterator<? extends E> it = collection.iterator(); |
| 188 | while (it.hasNext()) { |
| 189 | elementData[location++] = it.next(); |
| 190 | } |
| 191 | elementCount += size; |
| 192 | modCount++; |
| 193 | return true; |
| 194 | } |
| 195 | throw new ArrayIndexOutOfBoundsException(location); |
| 196 | } |
| 197 | |
| 198 | /** |
| 199 | * Adds the objects in the specified collection to the end of this vector. |