I have an iterator of strings from fieldNames of JsonNode
:
val mm = ... //JsonNode
val xs = mm.fieldNames()
I want to loop over the fields while keeping count, something like:
when mm.size() {
1 -> myFunction1(xs[0])
2 -> myFunction2(xs[0], xs[1])
3 -> myFunction3(xs[0], xs[1], xs[2])
else -> print("invalid")
}
Obviously the above code does not work as xs
the Iterator cannot be indexed like so. I tried to see if I can convert the iterator to list by mm.toList()
but that does not exist.
How can I achieve this?