Cast a Null String into Integer

前端 未结 7 881
闹比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.

提交回复
热议问题