How to check if a String is numeric in Java

前端 未结 30 2581
盖世英雄少女心
盖世英雄少女心 2020-11-21 05:26

How would you check if a String was a number before parsing it?

30条回答
  •  北荒
    北荒 (楼主)
    2020-11-21 06:02

    You can use NumberUtils.isCreatable() from Apache Commons Lang.

    Since NumberUtils.isNumber will be deprecated in 4.0, so use NumberUtils.isCreatable() instead.

提交回复
热议问题