"List interface provides two methods to efficiently insert and remove multiple elements" - Does anyone know what the second method is?

Viewed 93

From the Java docs I see the "The List interface provides two methods to efficiently insert and remove multiple elements at an arbitrary point in the list.". Presumably

  1. addAll​(int index, Collection<? extends E> c) What's the second method?

Or is this in reference to removeAll​(Collection<?> c) and addAll​(Collection<? extends E> c)?

https://docs.oracle.com/en/java/javase/15/docs/api/java.base/java/util/List.html

1 Answers

This is a documentation bug. See JDK-8215983.

As you noted, it's possible to insert multiple elements at an arbitrary point in the list by using addAll(int, Collection). There's no corresponding single method to remove multiple elements starting at an arbitrary, particular point in the list. That can be accomplished via the subList(from, to).clear() method sequence.

The docs might be referring to the removeRange method, which is a protected method on AbstractList. That's intended for use by lists that are implemented using AbstractList, not for general users of the List interface. It might have been present in an earlier evolutions of the List interface, but the reference to it in the List documentation was never cleaned up.

Related