I've searched, but there doesn't seem to be any way to easily remove a
range of values from a Collection (specifically a Vector). I did see
that the Vector class has the method removeRange(int fromIndex, int
toIndex) but this is a protected method.
If I am looking in the wrong spot, could someone point me in the right
direction (or, if I have to write my own method, it would be good to
know that too).
Thank you
Patricia Shanahan - 06 Mar 2007 23:33 GMT
> I've searched, but there doesn't seem to be any way to easily remove a
> range of values from a Collection (specifically a Vector). I did see
[quoted text clipped - 4 lines]
> direction (or, if I have to write my own method, it would be good to
> know that too).
See the subList method.
Patricia
Tom Hawtin - 06 Mar 2007 23:35 GMT
> I've searched, but there doesn't seem to be any way to easily remove a
> range of values from a Collection (specifically a Vector). I did see
> that the Vector class has the method removeRange(int fromIndex, int
> toIndex) but this is a protected method.
You can probably search through the source and see where removeRange is
called from.
From the documentation for List.subList:
"This method eliminates the need for explicit range operations (of the
sort that commonly exist for arrays). Any operation that expects a list
can be used as a range operation by passing a subList view instead of a
whole list. For example, the following idiom removes a range of elements
from a list:
"list.subList(from, to).clear();"
Note that it is a half-open range. The higher index is exclusive.
Tom Hawtin