Java string matching problem
•
Java
I face a very basic problem Sometimes small things can take a whole day:(
I try to match 2 strings, and if it matches, it should return true
Now I'm using it
if (var1.indexOf(var2) >= 0) { return true; }
However, if the value of VAR1 is "maintain" and the value of var2 is "inta" or "ain", it still returns true: (. Is there any method in Java that can perform full-text matching instead of partial matching? For example
if("mango"=="mango"){ return true; }
Thank you!
Solution
Why not use the built-in string equals () method?
return var1.equals(var2);
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码