This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Features new in Java 7 and the fly likes Collections Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Features new in Java 7
Bookmark "Collections" Watch "Collections" New topic
Author

Collections

Sundarajan Srinivasan
Greenhorn

Joined: Apr 27, 2012
Posts: 8
Is that possible to delete a range of index in a list, instead of clearing it completely or deleting by each index values.
Koen Aerts
Ranch Hand

Joined: Feb 07, 2012
Posts: 344

Yes. For instance ArrayList has a "removeRange(int fromIndex, int toIndex)" method. Collection has "removeAll(Collection<?> c)" and "retainAll(Collection<?> c)" methods. Take a look at the JDK 1.7 API.
Sundarajan Srinivasan
Greenhorn

Joined: Apr 27, 2012
Posts: 8
Koen Aerts wrote:Yes. For instance ArrayList has a "removeRange(int fromIndex, int toIndex)" method. Collection has "removeAll(Collection<?> c)" and "retainAll(Collection<?> c)" methods. Take a look at the JDK 1.7 API.


Thank you so much Koen Aerts. Checked it.
Sundarajan Srinivasan
Greenhorn

Joined: Apr 27, 2012
Posts: 8
Sundarajan Srinivasan wrote:
Koen Aerts wrote:Yes. For instance ArrayList has a "removeRange(int fromIndex, int toIndex)" method. Collection has "removeAll(Collection<?> c)" and "retainAll(Collection<?> c)" methods. Take a look at the JDK 1.7 API.


ArrayList does not contain any method named removeRange(int fromIndex,int toIndex).Eventhough it is available, I am unable to use it
Koen Aerts
Ranch Hand

Joined: Feb 07, 2012
Posts: 344

Sundarajan Srinivasan wrote:ArrayList does not contain any method named removeRange(int fromIndex,int toIndex).Eventhough it is available, I am unable to use it

It is there, except it is protected. Check the following article about this: http://stackoverflow.com/questions/2289183/why-is-javas-abstractlists-removerange-method-protected
Sundarajan Srinivasan
Greenhorn

Joined: Apr 27, 2012
Posts: 8
Koen Aerts wrote:
Sundarajan Srinivasan wrote:ArrayList does not contain any method named removeRange(int fromIndex,int toIndex).Eventhough it is available, I am unable to use it

It is there, except it is protected. Check the following article about this: http://stackoverflow.com/questions/2289183/why-is-javas-abstractlists-removerange-method-protected


Yeah Got it at last. Will accomplish using the method subList(int fromIndex,int toIndex).clear();. Thank you once again.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Collections
 
Similar Threads
String.split
Struts 2: mathematical operations on status.index
IndexOutOfBoundsException
File.exists() Problem
ArrayList and IndexOutOfBoundsException