Skip to content

Arrays.asList doesn’t return the ArrayList you know

April 9, 2013

I recently wrongly assumed that java.util.Arrays.asList, would return java.util.ArrayList, but it doesn’t. Instead, java.util.Arrays has a private static nested class that extends AbstractList on it’s own. Calling a method like ‘retainAll()” fails because of missing methods that exist in java.util.ArrayList, but NOT in java.util.Arrays$ArrayList.


From → Java

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: