This is very important to understand the difference between two version of creating collection in Java-
- final List list1 = new ArrayList();
- List list2 = Arrays.asList(…);
Here in 1 type making list as final I am making collection final collection which mean I can not change its reference, but I can add/remove elements in list1.
In list2 adding/removing elements is not allowed and throw runtime exception java.lang.UnsupportedOperationException
Hope this article helps you to understand the difference between final collection and fixed sized collection version. Use them wisely.