user3220962
user3220962

Reputation: 371

Check Equality of two Strings in java

I've got 2 Strings and both are the same:

alter follower  = 2014-02-23T18:41:35Z
neuster follower= 2014-02-23T18:41:35Z

I do an if/else so if they're the same the program should just display values and if not it should announce the new name (follower), but somehow, it's only doing the else statement when they're the same...

my code;

///////////////////
/// New Follower Trigger
/////////////////// 

if(followdateold.toLowerCase().equals(latestfollowerdate.toLowerCase())) {
    System.out.println("Noch kein neuer Follower... :( ");
    System.out.println("Noch kein neuer Follower... :( ");
}else{
    System.out.println("alter follower= "+followdateold);
    System.out.println("neuster follower= "+latestfollowerdate);
        sendMessage("#"+YBot.MyBot.ownerchannel+"", "Danke für deinen follow, "+fname);
        FollowerChecker.Writer();

        try {
            FollowerChecker.readFile("donottouch.txt");
        } catch (IOException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
    }

Upvotes: 0

Views: 134

Answers (2)

Dracosni
Dracosni

Reputation: 87

Try using

followdateold.equalsIgnoreCase(latestfollowerdate)

maybe that would work.

Upvotes: 0

Kakarot
Kakarot

Reputation: 4252

Its possible that there are some leading or trailing whitespaces in the 2 strings, you should trim the whitespace before comparing the strings, try this :

if(followdateold.trim().toLowerCase().equals(latestfollowerdate.trim().toLowerCase())) {

Upvotes: 2

Related Questions