Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / March 2007

Tip: Looking for answers? Try searching our database.

Delete Range of Values from Collection

Thread view: 
Jason Cavett - 06 Mar 2007 23:22 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.

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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.