Is there an alternative to StringUtils.isNumeric that does what I mean?

apache-commons, java

Solution

Try `isNumber(String)` from `org.apache.commons.lang.math.NumberUtils`.

Checks whether the String [is] a valid Java number.

Valid numbers include hexadecimal marked with the 0x qualifier, scientific notation and numbers marked with a type qualifier (e.g. 123L).

`Null` and empty String will return `false`.

UPDATE -

`isNumber(String)` is now deprecated. Use `isCreatable(String)` instead.

Thank you eav for pointing it out.

Problem

StringUtils.isNumeric returns true for "" and false for 7.8. This is of course it's documented behavior, but really not the most convenient for me. Is there something else (ideally in commons.lang) that provides an isActuallyNumeric?

Original source