This week's giveaway is in the Java/Jakarta EE forum.
We're giving away four copies of Java EE 8 High Performance and have Romain Manni-Bucau on-line!
In my opinion, this is much easier to read. Note that Date also overloads the equals() method, so you don't even need to convert the Date to a String first. In other words, you can reduce this method to a single line of code:

Notice that I am just comparing each member field for equality here. Also, this is a much more general solution because it only relies on the fact that the classes involved override the equals() method themselves. In my mind, this makes more sense when you are implementing a custom equals() method than it does to rely on classes overriding toString(). On the other hand, if I were implementing a custom toString() method, I would rely on the toString() method from other classes.

I hope this helps. And welcome to the Ranch!


[ August 27, 2005: Message edited by: Layne Lund ]
[ August 27, 2005: Message edited by: Layne Lund ]
christopher persinger
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i was told by someone in another forum that i need to make my equals method ... (Object anOrder) .. instead of (Order anOrder)... does this matter??

also, on the equals idea you just gave me.. i am needing to compare each individual letter in order to be able to place them in alphabetical order.. does the code you give me do that?

To do a great right, do a little wrong - shakepeare. twisted little ad:
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!