filterTo
val nc = mutableListOf<Int>()
val numbers = arrayOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
// 筛选出所有偶数
numbers.filterTo(nc) { it % 2 == 0 }
// 输出:偶数: [2, 4, 6, 8, 10]
_console.log("偶数: ", nc)
val wc = mutableListOf<String>()
val words = arrayOf("hello", "world", "kotlin", "android")
// 筛选出长度大于 5 的单词
words.filterTo(wc) { it.count() > 5 }
// 输出:长度大于 5 的单词: [kotlin, android]
_console.log("长度大于 5 的单词: ", wc)
def nc = $objectWrappers.wrap($iterables.mutableListOf())
def numbers = $objectWrappers.wrap($arrays.arrayOf($plugins.loadClass("java.lang.Integer"), 1, 2, 3, 4, 5, 6, 7, 8, 9, 10))
// 筛选出所有偶数
numbers.filterTo(nc) { it % 2 == 0 }
// 输出:偶数: [2, 4, 6, 8, 10]
$console.log("偶数: ", nc)
def wc = $objectWrappers.wrap($iterables.mutableListOf())
def words = $objectWrappers.wrap($arrays.arrayOf($plugins.loadClass("java.lang.String"), "hello", "world", "kotlin", "android"))
// 筛选出长度大于 5 的单词
words.filterTo(wc) { $objectWrappers.wrap(it).count() > 5 }
// 输出:长度大于 5 的单词: [kotlin, android]
$console.log("长度大于 5 的单词: ", wc)
let nc = $objectWrappers.wrap($iterables.mutableListOf())
let numbers = $objectWrappers.wrap($arrays.arrayOf($plugins.loadClass("java.lang.Integer"), 1, 2, 3, 4, 5, 6, 7, 8, 9, 10))
// 筛选出所有偶数
numbers.filterTo(nc, (it) => it % 2 == 0)
// 输出:偶数: [2, 4, 6, 8, 10]
$console.log("偶数: ", nc)
let wc = $objectWrappers.wrap($iterables.mutableListOf())
let words = $objectWrappers.wrap($arrays.arrayOf($plugins.loadClass("java.lang.String"), "hello", "world", "kotlin", "android"))
// 筛选出长度大于 5 的单词
words.filterTo(wc, (it) => $objectWrappers.wrap(it).count() > 5)
// 输出:长度大于 5 的单词: [kotlin, android]
$console.log("长度大于 5 的单词: ", wc)
local nc = _objectWrappers:wrap(_iterables:mutableListOf())
local numbers = _objectWrappers:wrap(_arrays:arrayOf(_plugins:loadClass("java.lang.Integer"), 1, 2, 3, 4, 5, 6, 7, 8, 9, 10))
-- 筛选出所有偶数
numbers:filterTo(nc, function(it)
return it % 2 == 0
end)
-- 输出:偶数: [2, 4, 6, 8, 10]
_console:log("偶数: ", nc)
local wc = _objectWrappers:wrap(_iterables:mutableListOf())
local words = _objectWrappers:wrap(_arrays:arrayOf(_plugins:loadClass("java.lang.String"), "hello", "world", "kotlin", "android"))
-- 筛选出长度大于 5 的单词
words:filterTo(wc, function(it)
return _objectWrappers:wrap(it):count() > 5
end)
-- 输出:长度大于 5 的单词: [kotlin, android]
_console:log("长度大于 5 的单词: ", wc)
<?php
$nc = $objectWrappers->wrap($iterables->mutableListOf());
$numbers = $objectWrappers->wrap($arrays->arrayOf($plugins->loadClass("java.lang.Long"), 1, 2, 3, 4, 5, 6, 7, 8, 9, 10));
// 筛选出所有偶数
$numbers->filterTo($nc, function ($it) {
return $it % 2 == 0;
});
// 输出:偶数: [2, 4, 6, 8, 10]
$console->log("偶数: ", $nc);
$wc = $objectWrappers->wrap($iterables->mutableListOf());
$words = $objectWrappers->wrap($arrays->arrayOf($plugins->loadClass("java.lang.String"), "hello", "world", "kotlin", "android"));
// 筛选出长度大于 5 的单词
$words->filterTo($wc, function ($it) use ($objectWrappers) {
return $objectWrappers->wrap($it)->count() > 5;
});
// 输出:长度大于 5 的单词: [kotlin, android]
$console->log("长度大于 5 的单词: ", $wc);
nc = _objectWrappers.wrap(_iterables.mutableListOf())
numbers = _objectWrappers.wrap(_arrays.arrayOf(_plugins.loadClass("java.lang.Long"), 1, 2, 3, 4, 5, 6, 7, 8, 9, 10))
# 筛选出所有偶数
numbers.filterTo(nc, lambda it: it % 2 == 0)
# 输出:偶数: [2, 4, 6, 8, 10]
_console.log("偶数: ", nc)
wc = _objectWrappers.wrap(_iterables.mutableListOf())
words = _objectWrappers.wrap(
_arrays.arrayOf(_plugins.loadClass("java.lang.String"), "hello", "world", "kotlin", "android"))
# 筛选出长度大于 5 的单词
words.filterTo(wc, lambda it: _objectWrappers.wrap(it).count() > 5)
# 输出:长度大于 5 的单词: [kotlin, android]
_console.log("长度大于 5 的单词: ", wc)
# encoding: utf-8
nc = $objectWrappers.wrap($iterables.mutableListOf())
numbers = $objectWrappers.wrap($arrays.arrayOf($plugins.loadClass("java.lang.Long"), 1, 2, 3, 4, 5, 6, 7, 8, 9, 10))
# 筛选出所有偶数
numbers.filterTo(nc) { |it| it % 2 == 0 }
# 输出:偶数: [2, 4, 6, 8, 10]
$console.log("偶数: ", nc)
wc = $objectWrappers.wrap($iterables.mutableListOf())
words = $objectWrappers.wrap($arrays.arrayOf($plugins.loadClass("java.lang.String"), "hello", "world", "kotlin", "android"))
# 筛选出长度大于 5 的单词
words.filterTo(wc) { |it| $objectWrappers.wrap(it).count() > 5 }
# 输出:长度大于 5 的单词: [kotlin, android]
$console.log("长度大于 5 的单词: ", wc)
Last modified: 29 August 2025