How to check if a String is numeric in Java

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

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

30条回答
  •  你的背包
    2020-11-21 05:47

    if you are on android, then you should use:

    android.text.TextUtils.isDigitsOnly(CharSequence str)
    

    documentation can be found here

    keep it simple. mostly everybody can "re-program" (the same thing).

提交回复
热议问题