In the answers here lately, I found some different habits (or flavours). So I wonder when and why is the use of Java's System.arraycopy(...) preferable to something like Collection.addAll(...)? When not?
Edit: It boils down to arrays vs. collections. Thanks so far. But which can be handled more effeciently by the computer or is... well... better for programmers?
Thanks
Mike
[;-)
Well, for one thing System.arraycopy(...) works on arrays, and Collection.addAll() on collections - so what you can use depends on what kind of objects you have to work with.
The alternative to System.arraycopy(...) with arrays is writing a loop and copying elements manually. This is
System.arraycopy(...) is a native method that can use fast memory copy routines provided by the OS.Arrays are not Collections. So whenever you need to copy things from an array to another array, use System.arraycopy. If you need to add things from one Collection to another Collection, use Collection.add() or Collection.addAll().
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With