Kotlin iterator to list? : <p>I have an iterator of strings from <a href="http://fasterxml.github.io/jackson-databind/javadoc/2.7/com/fasterxml/jackson/databind/JsonNode.html#fieldNames%28%29" rel="noreferrer">fieldNames</a> of <code>JsonNode</code>:</p>

<pre><code>val mm = ... //JsonNode
val xs = mm.fieldNames()
</code></pre>

<p>I want to loop over the fields while keeping count, something like:</p>

<pre><code>when mm.size() {
  1 -&gt; myFunction1(xs[0])
  2 -&gt; myFunction2(xs[0], xs[1])
  3 -&gt; myFunction3(xs[0], xs[1], xs[2])
  else -&gt; print("invalid")
}
</code></pre>

<p>Obviously the above code does not work as <code>xs</code> the Iterator cannot be indexed like so. I tried to see if I can convert the iterator to list by <code>mm.toList()</code> but that does not exist.</p>

<p>How can I achieve this? </p>
