简体   繁体   中英

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();
        }
    }

可能在2个字符串中有一些前导或尾随空格,你应该在比较字符串之前修剪空格,试试这个:

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

Try using

followdateold.equalsIgnoreCase(latestfollowerdate)

maybe that would work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM