zip
val numbers = arrayOf(1, 2, 3)
val letters = listOf("a", "b", "c")
// 将两个数组的元素按顺序配对,配对后的元素: [(1, a), (2, b), (3, c)]
numbers.zip(letters) { o1, o2 -> o1 to o2 }.forEach {
_console.log(it)
}
def numbers = $objectWrappers.wrap($arrays.arrayOf($plugins.loadClass("java.lang.Integer"), 1, 2, 3))
def letters = $iterables.listOf("a", "b", "c")
// 将两个数组的元素按顺序配对,配对后的元素: [(1, a), (2, b), (3, c)]
numbers.zip(letters) { o1, o2 -> o1 + o2 }.forEach {
$console.log(it)
}
let numbers = $objectWrappers.wrap($arrays.arrayOf($plugins.loadClass("java.lang.Integer"), 1, 2, 3))
let letters = $iterables.listOf("a", "b", "c")
// 将两个数组的元素按顺序配对,配对后的元素: [(1, a), (2, b), (3, c)]
numbers.zip(letters, (o1, o2) => o1 + o2).forEach((it) => {
$console.log(it)
})
local numbers = _objectWrappers:wrap(_arrays:arrayOf(_plugins:loadClass("java.lang.Integer"), 1, 2, 3))
local letters = _iterables:listOf("a", "b", "c")
-- 将两个数组的元素按顺序配对,配对后的元素: [(1, a), (2, b), (3, c)]
numbers:zip(letters, function(o1, o2)
return o1 .. o2
end) :forEach(function(it)
_console:log(it)
end)
<?php
$numbers = $objectWrappers->wrap($arrays->arrayOf($plugins->loadClass("java.lang.Long"), 1, 2, 3));
$letters = $iterables->listOf("a", "b", "c");
// 将两个数组的元素按顺序配对,配对后的元素: [(1, a), (2, b), (3, c)]
$numbers->zip($letters, function ($o1, $o2) {
return $o1 . $o2;
})->forEach(function ($it) use ($console) {
$console->log($it);
});
numbers = _objectWrappers.wrap(_arrays.arrayOf(_plugins.loadClass("java.lang.Long"), 1, 2, 3))
letters = _iterables.listOf("a", "b", "c")
# 将两个数组的元素按顺序配对,配对后的元素: [(1, a), (2, b), (3, c)]
numbers.zip(letters, lambda o1, o2: str(o1) + o2).forEach(lambda it: _console.log(it))
# encoding: utf-8
numbers = $objectWrappers.wrap($arrays.arrayOf($plugins.loadClass("java.lang.Long"), 1, 2, 3))
letters = $iterables.listOf("a", "b", "c")
# 将两个数组的元素按顺序配对,配对后的元素: [(1, a), (2, b), (3, c)]
numbers.zip(letters) { |o1, o2| o1.to_s + o2 }.forEach { |it|
$console.log(it)
}
Last modified: 29 April 2025