This week's book giveaway is in the OCPJP forum. We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line! See this thread for details.
Mei Jones wrote:
I know there should be a issue with my comparison here --> if ((sdf.format(d)).toString() == s)
When comparing objects' states ("contents"), use equals(), not ==. This includes comparing Strings for equality. The == operator tests if two references have the same value (both point to the same object or both are null). The equals() method, if properly written, tells if two objects have equal "contents" by whatever equality semantics are defined for the class in question.
Also, you don't need the toString() there, since format() returns a String.
Also, if you're comparing dates, you should compare them as Dates, not as Strings.