java - What is the time complexity of Collection.toArray()? -
what time complexity of method collection.toarray()
? o(n), if yes benefits offer on looping , individually assigning values in list array( beside nice , effort of course).
because toarray()
method abstract, speaking time complexity in general makes no sense.
however, native implementations, complexity indeed o(n)
. noteworthy collection
subinterface of iterable
. quite absurd implement iterable
cannot efficiently iterated over.
the fact implementation of toarray()
kept open, leaving space optimizations. there may approaches faster building array using simple iteration (array copying, running in multiple threads...). however, default implementaion in abstractcollection
uses exact approach mention in question.
Comments
Post a Comment