Hello: 1. I use System.arraycopy(originalArray, 0, copiedArray, 0, originalArray.length); then what's the difference between originalArray.equals(copiedArray) and Arrays.equals(originalArray, copiedArray) ?
2. I use String clonedArray = (String)originalArray.clone(); then what's the difference between originalArray.equals(clonedArray)) and Arrays.equals(originalArray, clonedArray)) ?
Originally posted by Campbell Ritchie: 1, 2. Don't know. What does it say in the API for those methods?
Well, to be fair, there is no Javadoc for String.equals(); you have to read the Java Language Spec to find out what it does. For any array type, the built-in equals() method is just the one inherited from Object, which compares the target to the argument using "=="; i.e., it tests if the two arrays are the same physical object.
Arrays.equals(), on the other hand, compares the two arrays for length, type, and contents, as you'd expect. They can be two different objects, as long as they're "the same".
Originally posted by sarah Marsh: arraycopy method copies all or part of an array into all or part of another array, then the another array is a new object, right?
You have to create 'another array' before calling arraycopy. arraycopy does not create it for you.
Originally posted by sarah Marsh: obj1.equals(obj2) should be different from ==, right?
Depends on the type of obj1. If it is a class that has not overridden the equals() method of Object, then obj1.equals(obj2) will be the same as obj1 == obj2. i.e. it will only be true if obj1 and obj2 reference the same object. [ June 22, 2006: Message edited by: Joanne Neal ]