Saurabh, this is from the documentation of the asList(T[] a) method
If the list fits in the specified array with room to spare (i.e., the array has more elements than the list), the element in the array immediately following the end of the list is set to null. (This is useful in determining the length of the list only if the caller knows that the list does not contain any null elements.)
So since your list fits into the array, the last spot is set to null and while iterating it, the compiler tries to unbox it to int (from Integer) and thus you get the exception...
I didnt understand why such error could happen ..
I knew that the array returned could grow larger in size if the supplied array doesnt have enough room,
but this is really another story.
Btw it's the api doc for the List's public Object[] toArray(Object[] a), not asList()
The usability of the asList() shall be taken in when you wants to play around the arrays except modifying it.
Since arrays can not be scaled or diminised at the runtime so is the list created on the top of it has no provistion for doing the same.
Same can be derived after seeing the JDK source code as well.
So there is no problem as such with asList().There are many alternative ways to sort out your porblem as discussed above.