• Post Reply Bookmark Topic Watch Topic
  • New Topic

Getting an exception when using removeAll()  RSS feed

 
Paul Mrozik
Ranch Hand
Posts: 117
Chrome Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No clue as to why this is happening. Both hdList and smallerList are of type <HotDog>, but I get an UnsupportedExceptionOperation.

Here's the code:


What gives? Anyone?
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You might want to go back and re-read the docs for Arrays.asList.
 
Paul Mrozik
Ranch Hand
Posts: 117
Chrome Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeff Verdegan wrote:You might want to go back and re-read the docs for Arrays.asList.


Nice, it returns a fixed-size array. Okay, now I have to find a workaround. Thanks.
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Mrozik wrote:Okay, now I have to find a workaround. Thanks.



 
Paul Mrozik
Ranch Hand
Posts: 117
Chrome Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeff Verdegan wrote:
Paul Mrozik wrote:Okay, now I have to find a workaround. Thanks.





Thank you Jeff, I never thought of it that way. In fact, it solved another problem with this:



But I fail to understand why this did not work:



The compiler shoots out with a java.util.ConcurrentModificationException.

The API states "Returns a view of the portion of this list between the specified fromIndex, inclusive, and toIndex, exclusive."

So does that mean that smallerList actually accesses the same list (just a much smaller portion) and so it tries to remove and access the two items at the same time, thus the exception?


 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Mrozik wrote:
The API states "Returns a view of the portion of this list between the specified fromIndex, inclusive, and toIndex, exclusive."

So does that mean that smallerList actually accesses the same list (just a much smaller portion) and so it tries to remove and access the two items at the same time, thus the exception?


Exactly.

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!