0

The values of zerosMatcherNext.group(1) and zerosMatcher.group(1) are being evaluated as String with value 0 but the comparison zerosMatcherNext.group(1) == zerosMatcher.group(1) returns false. What is the explanation for such a strange behavior?

UPDATE:

but zerosMatcherNext.group(1).equals(zerosMatcher.group(1)) returns true

J.Olufsen
  • 13,415
  • 44
  • 120
  • 185

1 Answers1

1

String comparison should be made with equals

    new String("0") == new String("0"); // return false
    new String("0").equals(new String("0"); // returns true

Java comparison with == of two strings is false?

Community
  • 1
  • 1
Master Slave
  • 27,771
  • 4
  • 57
  • 55