tag:blogger.com,1999:blog-694855878384792308.post7396818930631479653..comments2024-03-21T06:26:49.387-07:00Comments on Java67: How to create and initialize List or ArrayList in one line in Java? Examplejavin paulhttp://www.blogger.com/profile/15028902221295732276noreply@blogger.comBlogger3125tag:blogger.com,1999:blog-694855878384792308.post-46359301361926076702020-04-30T11:14:42.128-07:002020-04-30T11:14:42.128-07:00Cool!Cool!Anitahttps://www.blogger.com/profile/06024819529023051048noreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-66553363647948776422015-08-05T00:07:39.381-07:002015-08-05T00:07:39.381-07:00That's not true, even calling remove() method ...That's not true, even calling remove() method on List returned by Arrays.asList will throw UnsupportedException as seen below :<br />Exception in thread "main" java.lang.UnsupportedOperationException<br /> at java.util.AbstractList.remove(AbstractList.java:161)<br /> at java.util.AbstractList$Itr.remove(AbstractList.java:374)<br /> at java.util.AbstractCollection.remove(AbstractCollection.java:291)<br /><br />Only method which works without exception and modifies the list is set(index, value), which you can use to update the List. Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-29376292318908845842015-06-25T02:42:16.658-07:002015-06-25T02:42:16.658-07:00There is one correction required in your article. ...There is one correction required in your article. Calling remove() method on List returned from Arrays.asList() doesn't throw any UnSupportedOperationException but calling add() method will throw the exception. Harinathhttps://www.blogger.com/profile/10009935471199557394noreply@blogger.com