clone vs copying Array in Java?
I have this bit of code, where I am making a copy of an array. using
System.arraycopy seems more verbose than clone(). but both give the same
results. are there any advantages of one over the other? here is the code:
import java.util.*;
public class CopyArrayandArrayList {
public static void main(String[] args){
//Array copying
char[] copyFrom = { 'd', 'e', 'c', 'a', 'f', 'f', 'e'};
char[] copyTo = new char[7];
System.arraycopy(copyFrom, 0, copyTo, 0, 7);
char[] copyThree = new char[7];
copyThree=copyFrom.clone();
}
}
No comments:
Post a Comment