does Kotlin have some kind of index type? for exam...
# getting-started
s
does Kotlin have some kind of index type? for example, I want to pass a List, and an index into that List. I could pass just an Int as the index, but it's possible that is outside the bounds of the list. I was wondering if there was some kind of type-safe way to tie the two together?
🚫 1
🆗 1
h
Hmm, sounds like a job for a
List
? They are indexed by nature and if you need “empty” places, allow `null`able types.
Or do I miss something?
s
that's not quite what I want. Normally I'd pass just the sublist that I'm interested in, or just the element, but in this case, I need to know where in the list I am, and have access to the whole list
l
You might be interested in
list.getOrNull(index)
. It returns null if the index in out of bounds
👍 1
s
yeah, that seems like what I need. Thanks