Monday, May 17, 2010

Behind the scenes of Arrays.asList(T… a)

We all know that the method public static List asList(T... a) in Arrays class returns an ArrayList.

But if you try to add or remove an element on this returned arrayList, you get an UnsupportedOperationException. Why?

This is because the returned ArrayList is not of type java.util.ArrayList, instead, it is java.util.Arrays$ArrayList class. And this java.util.Arrays$ArrayList class does not override all the methods of AbstractList class.

That means Arrays.asList() returns you a fixed size list.

Refer this link http://tinyurl.com/26mxkxm for complete article.

No comments:

Post a Comment