For this, Java has a boolean data type, which can take the values as True or False, A boolean type is declared with the boolean keyword and can only take the values True or False. However, it is more common to return boolean values from boolean expressions, for conditional testing (see below):
public static void main(String[] args) {
String string = "-1234.15";
boolean numeric = true ;
numeric = string.matches("-?\\d+(\\.\\d+)?");
if(numeric)
System.out.println(string + " is a number");
else
System.out.println(string + " is not a number");
}
Happy coding.