This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Collections

 
Sundarajan Srinivasan
Greenhorn
Posts: 8
  • 0
  • 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
  • 0
  • 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
  • 0
  • 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
  • 0
  • 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
  • 0
  • 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
  • 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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic