Home  >  Article  >  Java  >  Java determines whether a string is double type

Java determines whether a string is double type

尚
Original
2019-11-22 09:40:448811browse

Java determines whether a string is double type

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn