Cast a Null String into Integer

前端 未结 7 911
闹比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条回答
  •  旧时难觅i
    2021-01-01 18:51

    Try below code:application will return 0 if the string is null else it will parse the string to int if string contains a number alone..

    Code:

    (str.equals("null")?0:Integer.parseInt(str))
    

提交回复
热议问题