File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Arrays.toArray : All my knowledge collapses ... 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 "Arrays.toArray : All my knowledge collapses ..." Watch "Arrays.toArray : All my knowledge collapses ..." New topic

Arrays.toArray : All my knowledge collapses ...

Cyril Bil

Joined: Oct 10, 2011
Posts: 9
Hi guys I just try this sample question :

I was sure at 110% that code compile and run without exception and .....

I go to the API doc and see

asList(T... a) : Returns a fixed-size list backed by the specified array.

ARghhhhhhhhhhh I thinhed that the first specifities of collection vs arrays was that collections has no fixed size ... :/

So my question : is there another method to fixed size for collection, and if there is another method is it only for List, ot also for set, map etc ...


Stephan van Hulst

Joined: Sep 20, 2010
Posts: 4635

In the standard API? I'm not sure. You probably shouldn't care either. Just read the method documentation carefully when you use a method.

The mind is a strange and wonderful thing. I'm not sure that it will ever be able to figure itself out, everything else, maybe. From the atom to the universe, everything, except itself.
Harsha Smith
Ranch Hand

Joined: Jul 18, 2011
Posts: 287
Yes, Arrays.asList(T...a) produces a list backed by the array. The size is fixed and also its very slow.

sakthi moorthy
Ranch Hand

Joined: Oct 17, 2007
Posts: 54
If you want to add or remove elements from List which was returned from Arrays.asList(dogs); method
change your code like following

Thanks & Regards
I agree. Here's the link:
subject: Arrays.toArray : All my knowledge collapses ...
It's not a secret anymore!