문제

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();
        }
    }
도움이 되었습니까?

해결책

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())) {

다른 팁

Try using

followdateold.equalsIgnoreCase(latestfollowerdate)

maybe that would work.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top