M8Test Help

mapIndexedTo

val dw = mutableListOf<String>() val words = arrayOf("hello", "world", "kotlin") // 将每个单词转换为带索引的字符串, 带索引的单词: [0: hello, 1: world, 2: kotlin] words.mapIndexedTo(dw) { index, word -> "$index" + ": " + word }.forEach { _console.log(it) }
def dw = $objectWrappers.wrap($iterables.mutableListOf()) def words = $objectWrappers.wrap($arrays.arrayOf($plugins.loadClass("java.lang.String"), "hello", "world", "kotlin")) // 将每个单词转换为带索引的字符串, 带索引的单词: [0: hello, 1: world, 2: kotlin] words.mapIndexedTo(dw) { index, word -> index + ": " + word }.forEach { $console.log(it) }
let dw = $objectWrappers.wrap($iterables.mutableListOf()) let words = $objectWrappers.wrap($arrays.arrayOf($plugins.loadClass("java.lang.String"), "hello", "world", "kotlin")) // 将每个单词转换为带索引的字符串, 带索引的单词: [0: hello, 1: world, 2: kotlin] words.mapIndexedTo(dw, (index, word) => index + ": " + word).forEach((it) => { $console.log(it) })
local dw = _objectWrappers:wrap(_iterables:mutableListOf()) local words = _objectWrappers:wrap(_arrays:arrayOf(_plugins:loadClass("java.lang.String"), "hello", "world", "kotlin")) -- 将每个单词转换为带索引的字符串, 带索引的单词: [0: hello, 1: world, 2: kotlin] words:mapIndexedTo(dw, function(index, word) return index .. ": " .. word end) :forEach(function(it) _console:log(it) end)
<?php $dw = $objectWrappers->wrap($iterables->mutableListOf()); $words = $objectWrappers->wrap($arrays->arrayOf($plugins->loadClass("java.lang.String"), "hello", "world", "kotlin")); // 将每个单词转换为带索引的字符串, 带索引的单词: [0: hello, 1: world, 2: kotlin] $words->mapIndexedTo($dw, function ($index, $word) { return $index . ": " . $word; })->forEach(function ($it) use ($console) { $console->log($it); });
dw = _objectWrappers.wrap(_iterables.mutableListOf()) words = _objectWrappers.wrap(_arrays.arrayOf(_plugins.loadClass("java.lang.String"), "hello", "world", "kotlin")) # 将每个单词转换为带索引的字符串, 带索引的单词: [0: hello, 1: world, 2: kotlin] words.mapIndexedTo(dw, lambda index, word: str(index) + ": " + word).forEach(lambda it: _console.log(it))
# encoding: utf-8 dw = $objectWrappers.wrap($iterables.mutableListOf()) words = $objectWrappers.wrap($arrays.arrayOf($plugins.loadClass("java.lang.String"), "hello", "world", "kotlin")) # 将每个单词转换为带索引的字符串, 带索引的单词: [0: hello, 1: world, 2: kotlin] words.mapIndexedTo(dw) { |index, word| index.to_s + ": " + word }.forEach { |it| $console.log(it) }
Last modified: 09 September 2025