Two Laptop Bag*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Doubt in list created by Arrays.asList( ) method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Doubt in list created by Arrays.asList( ) method" Watch "Doubt in list created by Arrays.asList( ) method" New topic
Author

Doubt in list created by Arrays.asList( ) method

neha verma
Ranch Hand

Joined: Jun 17, 2007
Posts: 37
When we write Arrays.asList(arr) we create a list. So cant we add anything to this list. Please see the example below. it gives me a runtime exception.Can somebody clarify.


Neha Verma
Freddy Wong
Ranch Hand

Joined: Sep 11, 2006
Posts: 959

If you read the API documentation carefully, the asList() methods returns a fixed-size List. Hence, adding an element into a List is not allowed.


SCJP 5.0, SCWCD 1.4, SCBCD 1.3, SCDJWS 1.4
My Blog
neha verma
Ranch Hand

Joined: Jun 17, 2007
Posts: 37
Thanks a lot
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Doubt in list created by Arrays.asList( ) method