
java determines whether a string is a double
/**
* 判断字符串是不是double型
* @param str
* @return
*/
public static boolean isNumeric(String str){
Pattern pattern = Pattern.compile("[0-9]+[.]{0,1}[0-9]*[dD]{0,1}");
Matcher isNum = pattern.matcher(str);
if( !isNum.matches() ){
return false;
}
return true;
}matches() method is used to detect whether a string matches a given regular expression.
Regular expression is a powerful tool for processing strings. It is not a feature of Java. It is also available in front-end JavaScript and so on. But compared to other old high-level languages, such as C/C, this is where Java is unique than them.
Regular expression usage:
1. String matching
2. String search
3. String replacement
For more java knowledge, please pay attention to java basic tutorial.
The above is the detailed content of Java determines whether a string is double type. For more information, please follow other related articles on the PHP Chinese website!