I need to make pattern which will accept String in format (_,_) e.g: "(0,0)", "(1,3)", "(5,8)" etc.
I wrote condition as following:
if (name.equals("(\\d,\\d)")) {
System.out.println("accepted")
}
name.equals() doesn't actually accept a regular expression. You're looking for matches(), which will accept a regular expression.
You'll also have to escape the parentheses, as they have special meaning in a regular expression.
if(name.matches("\\(\\d,\\d\\)") {
System.out.println("accepted");
}
String#equalsdoes not use regular expressions.java.lang.Stringfunctions that accept regular expressions arematches(s),replaceAll(s,s),replaceFirst(s,s),split(s), andsplit(s,i)