0

Why "==" or equals method doesn't work ?

        String levelSetting = ManageLogFile.getLevel(); 
        if (levelSetting != Log.Level.DEBUG.toString()) {
            System.out.println(Log.Level.DEBUG.toString());
            System.out.println(levelSetting);
            log.setData(null);
            }

With Result displayed :

DEBUG
DEBUG

It's the same String... But != doesn't work... I have also tried with equals method.. and same problem I have compare lenght and it's 5 for both.

Stephen P
  • 14,422
  • 2
  • 43
  • 67
Orion
  • 158
  • 1
  • 7
  • The reason that `==` and `!=` don't work most of the time is explained in the dup. If `String.equals(Object)` really doesn't work, then the two strings are NOT equal. (Hint: use a debugger and examine the strings character by character ...) – Stephen C Oct 26 '18 at 23:51
  • 1
    Hint: whitespaces are the same color as their background. – MC Emperor Oct 27 '18 at 06:59

0 Answers0