I have this code:
String string = "40' & 40' HC";
if(string.matches("&"))
System.out.println("Found");
But the condition won't be true. why? Help is appreciated. Thanks
On
It's misnamed .matches() method in JAVA. It tries and matches ALL the input.
String.matches returns whether the whole string matches the regex, not just any substring.
Use Pattern
String string = "40' & 40' HC";
Pattern p = Pattern.compile("&");
Matcher m = p.matcher(string);
if (m.find())
System.out.println("Found");
String.matches(String)is for a regular expression. I suggest you add anelse(and{}) and I believe you wantedcontainsand something like