• Post Reply Bookmark Topic Watch Topic
  • New Topic

Why List.removeAll() is not implemented  RSS feed

 
Kumar Raja
Ranch Hand
Posts: 550
2
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

Are there any specific reasons, why removeRange(int,int) is made protected in ArrayList, instead of making it public. I know that it is not defined in List interface, and probably that is the reason they did not make it public. But could there be any other reasons.

Also, I'm trying to remove a set of values from an ArrayList, but coming with UnsupportedOperationException, while calling removeAll. Am I doing anything wrong here ? How do I overcome this.



then when I read the documentation, I see them as optional methods, and hence might not have been implemented. So, apart from writing custom logic, is there no other way of removing some values from a list.

I thought of using removeRange(), but then its protected and I do not want to inherit ArrayList. Why so complicated ?

Thanks
 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kumar Raja wrote:then when I read the documentation, I see them as optional methods, and hence might not have been implemented. So, apart from writing custom logic, is there no other way of removing some values from a list.

Try reading the rest of the documentation. There's a method that does what you want.

edit: Sorry, misread the requirement. I thought you wanted to remove all the elements from the ArrayList.
 
Mahesh Murugaiyan
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Kumar,

Its interesting to see why removeRange is marked as protected. I will watch this thread to see if some one explains.

For the UnsupportedOperationException, getNextSet() should work properly.
How are you passing the list into this method? is that list obtained using Collections.unmodifiablelist ?

- Mahesh
 
dennis deems
Ranch Hand
Posts: 808
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you tell us what you are trying to achieve here? I am having a hard time imagining a scenario in which I would ever want to do what you describe.
 
Campbell Ritchie
Marshal
Posts: 56536
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since removeAll is specified in the List interface, all classes implementing it ought to have it as a public method. And, it is indeed public, as you can see in the documentation. Have you been using java.util.ArrayList, or have you come across another class with a similar name? Please explain more, because your question is difficult to understand.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!