Cast a Null String into Integer

前端 未结 7 880
闹比i
闹比i 2021-01-01 18:40

Is there any way to cast a null to Integer. The null is actually a String, which i am passing in my service layer that accepts it as an Integer. So, whenever i try to cast a

相关标签:
7条回答
  • 2021-01-01 19:02

    If you're using apache commons, there is an helper method that does the trick:

    NumberUtils.createInteger(myString)

    As said in the documentation:

    "convert a String to a Integer, handling hex and octal notations; returns null if the string is null; throws NumberFormatException if the value cannot be converted.

    0 讨论(0)
提交回复
热议问题