android - Regex Capture not equal to String of equal value -
this question has answer here:
- how compare strings in java? 23 answers
both strings appear same when printed console, not when compared using "=="
what doing wrong here?
string message = "rejected | ref id: captureme | name:"; pattern pattern = pattern.compile("\\bref id:\\s+(\\s+)"); matcher matcher = pattern.matcher(message); string matchedref = matcher.group(1); system.out.print(matchedref); prints: captureme
string myref = "captureme"; if(matchedref == myref){ system.out.print(true); } else{ system.out.print(false); } prints: false
to compare strings need use equals() method, not == operator.
if(matchedref.equals(myref)){ system.out.print(true); } else{ system.out.print(false); } you can read more string comparisons in this question.
Comments
Post a Comment