Hi, 

How about this:

```java
public static boolean isNumeric(String str, boolean allowDot) {
        if (str == null || str.isEmpty()) {
            return false;
        }
        int dotCount = 0;
        for (int i = 0; i < str.length(); i++) {
            if (str.charAt(i) == '.') {
                if (allowDot && dotCount == 0) {
                    dotCount++;
                    continue;
                } else {
                    return false;
                }
            }
            if (!Character.isDigit(str.charAt(i))) {
                return false;
            }
        }
        return true;
    }
```

This only need 1 loop. And also support something like "1." as a numeric.

```
jshell> Double.valueOf("1.")
$1 ==> 1.0
```

I also add some more unit test

```java
assertThat(StringUtils.isNumeric("123.3.3", true), is(false));
assertThat(StringUtils.isNumeric("123.", true), is(true));
```


[ Full content available at: 
https://github.com/apache/incubator-dubbo/pull/3093 ]
This message was relayed via gitbox.apache.org for 
[email protected]

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to