Posted on 2026-04-26 List底层实现是单向链表,所以慎用通过index的遍历方式,因为每次都要从头节点开始查。IndexedSeq可以使用 123for (i until nums.lenght) { println(nums(i))} 如果需要遍历List,又同时需要获取到index,可以改用迭代或zipWithIndex 1234567// 迭代// zipWithIndexfor ((value, index) <- nums.zipWithIndex) { ...} IndexedSeq 的实现主要包括: Array