Say I have a `val someSet: Set<String>? = se...
# announcements
d
Say I have a
val someSet: Set<String>? = setOf("this", "that", "this=3")
and I'd like to extract the 3 as an
Int
, is this the most ideomatic/efficient way to do it?
Copy code
someSet?.firstOrNull { it.startsWith("this=") }
					?.substringAfter("this=")
					?.toInt() ?: 0
d
Yeah, I guess that would work. There might be better options depending on the context but that seems fine for a one-off call.
d
Thanks for confirming! I was kinda thinking I was missing some magic stdlib function though...
d
I think you want
?.toIntOrNull() ?: 0
for the last bit
d
Right! Thanks for pointing that out 🙂