Is there a way to take a var myNullableInt: Int? a...
# getting-started
c
Is there a way to take a var myNullableInt: Int? and to get it as a string format... but if it's null to give me empty string? I have
Copy code
val curr = if (myNullableInt == null) "" else myNullableInt.toString()
s
Copy code
myNullableInt?.toString().orEmpty()
💡 2
c
Ah. I was trying
Copy code
myNullableInt.toString().orEmpty()
cool. knew i was doing something dumb
thanks
j
I usually find
?: ""
clearer than extensions on nullable values like
orEmpty
. So I would personally go for:
Copy code
myNullableInt?.toString() ?: ""
👍 3
K 1
⁉️ 1