Quantcast
Channel: What is more efficient: System.arraycopy or Arrays.copyOf? - Stack Overflow
Browsing latest articles
Browse All 11 View Live

Answer by Kevin Ng for What is more efficient: System.arraycopy or...

If you look at both the source code for System.arraycopy() of and Array.copyOf(), for performance. System.arraycopy() is C code, it operates directly on your array, it does not return any values, and...

View Article



Answer by cyberthreat for What is more efficient: System.arraycopy or...

Instead of debating, these are the actual results. Clearly, your choice will depend on how much data you want to copy. byte[] copy performance test 10,000,000 iterations 40b array.copyOfRange: 135ms...

View Article

Answer by Ambika for What is more efficient: System.arraycopy or Arrays.copyOf?

class ArrayCopyDemo { public static void main(String[] args) { char[] copyFrom = { 'd', 'e', 'c', 'a', 'f', 'f', 'e', 'i', 'n', 'a', 't', 'e', 'd' }; char[] copyTo = new char[7];...

View Article

Answer by matsev for What is more efficient: System.arraycopy or Arrays.copyOf?

Have you looked at the Sun's implementation of Arrays.copyOf()? public static int[] copyOf(int[] original, int newLength) { int[] copy = new int[newLength]; System.arraycopy(original, 0, copy, 0,...

View Article

Answer by gustafc for What is more efficient: System.arraycopy or Arrays.copyOf?

If you want an exact copy of an array (say, if you want to do a defensive copy), the most effective way of copying an array is probably using the array object's clone() method: class C { private int[]...

View Article


Answer by Stephen C for What is more efficient: System.arraycopy or...

While System.arraycopy is implemented natively, and is therefore could be1 faster than a Java loop, it is not always as fast as you might expect. Consider this example: Object[] foo = new...

View Article

Answer by Thilo for What is more efficient: System.arraycopy or Arrays.copyOf?

The difference is that Arrays.copyOf does not only copy elements, it also creates a new array. System.arraycopy copies into an existing array. Here is the source for Arrays.copyOf, as you can see it...

View Article

Answer by Humphrey Bogart for What is more efficient: System.arraycopy or...

System.arrayCopy is implemented natively, and hence will be faster than any Java code. I recommend you to use it.

View Article


Answer by Ry4an Brase for What is more efficient: System.arraycopy or...

System.arrayCopy is much faster. It's in system because it uses a direct memory copy outside of Java land. Use it when possible.

View Article


What is more efficient: System.arraycopy or Arrays.copyOf?

The toArray method in ArrayList, Bloch uses both System.arraycopy and Arrays.copyOf to copy an array. public <T> T[] toArray(T[] a) { if (a.length < size) // Make a new array of a's runtime...

View Article

Image may be NSFW.
Clik here to view.

Answer by aran for What is more efficient: System.arraycopy or Arrays.copyOf?

I posted this on another answer but may be useful here as well.I know this is not definitive by any means, as benchmarking these kinds of operations is a science on its own, but just for the fun, I...

View Article
Browsing latest articles
Browse All 11 View Live




Latest Images