android - Regex Capture not equal to String of equal value -


this question has answer here:

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

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -