| Author |
cloning, equals() - not understanding the behaviour
|
Jan Groth
Ranch Hand
Joined: Feb 03, 2004
Posts: 456
|
|
good evening from germany, i have a situation like this: a data class: a test class: the test fails at the last line. okay, first guess, easy: Data.readRecord(1) returns something else, that's the failure. but check this: this is the output of my runtime debugger: my question: if the two string arrays are equal on a line-by-line base, and have the same length, why does the direct equal() return true? and idea appreciated, thank you very much, Jan
|
 |
Jan Groth
Ranch Hand
Joined: Feb 03, 2004
Posts: 456
|
|
stupid me, the question is: if the two string arrays are equal on a line-by-line base, and have the same length, why does the direct equal() return false? ****** i would really appreciate a preview functionality in this forum...
|
 |
Ernest Friedman-Hill
author and iconoclast
Marshal
Joined: Jul 08, 2003
Posts: 24040
|
|
Because arrays don't override the "equals" method. Interestingly enough, someone just raised this very question over in the Java in General (Advanced) forum; see that thread for a more detailed answer. There's a family of overloaded two-argument static methods named java.util.Arrays.equals() which you can use to compare arrays elementwise.
|
[Jess in Action][AskingGoodQuestions]
|
 |
Jan Groth
Ranch Hand
Joined: Feb 03, 2004
Posts: 456
|
|
|
perfect answer, thanks a lot!
|
 |
 |
|
|
subject: cloning, equals() - not understanding the behaviour
|
|
|