Say if I have the following code
String sum = "(5+5)/2*6";
char[] bodmasChars = {'+','-','*','/','.'.'(',')'};
Is there a way to check whether the string contains any of the elements in my char[]?
Say if I have the following code
String sum = "(5+5)/2*6";
char[] bodmasChars = {'+','-','*','/','.'.'(',')'};
Is there a way to check whether the string contains any of the elements in my char[]?
A regex
String sum = "(5+5)/2*6";
if (sum.matches("(?s).*[-\\+\\*/\\.()].*")) { ...
(?s)
lets .
also match newlines.
[...]
is group of possible character or character ranges. Probably have a backslash too many.
You can try it with Regex or with Simple as :
String s="(5+5)/2*6";
if((s.contains("+")||(s.contains("-")||(s.contains("-"))||....))
{
System.out.println("yes");
}