• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Collections

 
Sundarajan Srinivasan
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 344
Java Linux Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 344
Java Linux Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic