• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

cloning, equals() - not understanding the behaviour

 
Ranch Hand
Posts: 456
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 456
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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...
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Jan Groth
Ranch Hand
Posts: 456
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
perfect answer, thanks a lot!
 
reply
    Bookmark Topic Watch Topic
  • New Topic