Forums Register Login

Arrays.toArray : All my knowledge collapses ...

+Pie Number of slices to send: Send
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 ...

Thanks.
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
Yes, Arrays.asList(T...a) produces a list backed by the array. The size is fixed and also its very slow.

+Pie Number of slices to send: Send
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
S.Sathiya
Surfs up space ponies, I'm making gravy without this lumpy, tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1189 times.
Similar Threads
Something that i dont understand : Passing Objects as elements at the end of a list
Using asList with Generics
Collections :List.add throws runtime Exception(Unsupported Exceptions)
Collections - Arrays.asList() / List.add()
trying to add items dynamically to spinner with alertdialog
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 03:51:30.