Results 1 to 4 of 4
Thread: Copy of array - difference
- 01-29-2012, 07:51 PM #1
Senior Member
- Join Date
- Jan 2012
- Posts
- 210
- Rep Power
- 2
Copy of array - difference
What is the difference between these two ways of array copying and which way is better?
Java Code:int[] array1 = new int[7]; int[] array2; array2 = array1.clone();Java Code:int[] array1 = new int[7]; int[] array2 = new int[array1.length]; System.arraycopy(array1, 0, array2, 0, array1.length);
-
Re: Copy of array - difference
For one, System.arraycopy has been optimized for copying arrays and is significantly faster at copying items from one array to another. AFAIK, neither does a deep copy though.
- 01-29-2012, 08:42 PM #3
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,604
- Blog Entries
- 7
- Rep Power
- 17
Re: Copy of array - difference
Also have a look at the Arrays utility class; it has a bunch of copyOf( ... ) methods; I bet they are optimized for the job.
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 01-29-2012, 09:15 PM #4
Senior Member
- Join Date
- Jan 2012
- Posts
- 210
- Rep Power
- 2
Similar Threads
-
What is the difference?
By sublixt in forum New To JavaReplies: 2Last Post: 08-14-2011, 03:37 AM -
What is the difference between
By arnab321 in forum New To JavaReplies: 2Last Post: 01-19-2009, 04:49 AM -
what is the difference between jsp and jsf?
By makpandian in forum JavaServer Pages (JSP) and JSTLReplies: 1Last Post: 12-31-2008, 05:55 PM -
Array initialization difference
By sln69 in forum Advanced JavaReplies: 2Last Post: 10-10-2008, 02:38 AM -
Difference between ASP and JSP
By barney in forum JavaServer Pages (JSP) and JSTLReplies: 1Last Post: 08-07-2007, 07:15 AM


1Likes
LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks