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

Java determines whether a string is double type

Release: 2019-11-22 09:40:44
Original
8841 people have browsed it

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; 
}
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template