M8Test Help

filterIndexedTo

val nc = mutableListOf<Int>() val numbers = arrayOf(10, 20, 30, 40, 50, 60) // 筛选出索引为偶数的元素 numbers.filterIndexedTo(nc) { index, _ -> index % 2 == 0 } // 输出:索引为偶数的元素: [10, 30, 50] _console.log("索引为偶数的元素: ", nc) val wc = mutableListOf<String>() val words = arrayOf("hello", "world", "kotlin", "android") // 筛选出索引为奇数且长度大于 5 的单词 words.filterIndexedTo(wc) { index, word -> index % 2 != 0 && word.count() > 5 } // 输出:筛选后的单词: [android] _console.log("筛选后的单词: ", wc)
def nc = $objectWrappers.wrap($iterables.mutableListOf()) def numbers = $objectWrappers.wrap($arrays.arrayOf($plugins.loadClass("java.lang.Integer"), 10, 20, 30, 40, 50, 60)) // 筛选出索引为偶数的元素 numbers.filterIndexedTo(nc) { index, _ -> index % 2 == 0 } // 输出:索引为偶数的元素: [10, 30, 50] $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.filterIndexedTo(wc) { index, word -> index % 2 != 0 && $objectWrappers.wrap(word).count() > 5 } // 输出:筛选后的单词: [android] $console.log("筛选后的单词: ", wc)
let nc = $objectWrappers.wrap($iterables.mutableListOf()) let numbers = $objectWrappers.wrap($arrays.arrayOf($plugins.loadClass("java.lang.Integer"), 10, 20, 30, 40, 50, 60)) // 筛选出索引为偶数的元素 numbers.filterIndexedTo(nc, (index, _) => index % 2 == 0) // 输出:索引为偶数的元素: [10, 30, 50] $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.filterIndexedTo(wc, (index, word) => index % 2 != 0 && $objectWrappers.wrap(word).count() > 5 ) // 输出:筛选后的单词: [android] $console.log("筛选后的单词: ", wc)
local nc = _objectWrappers:wrap(_iterables:mutableListOf()) local numbers = _objectWrappers:wrap(_arrays:arrayOf(_plugins:loadClass("java.lang.Integer"), 10, 20, 30, 40, 50, 60)) -- 筛选出索引为偶数的元素 numbers:filterIndexedTo(nc, function(index) return index % 2 == 0 end) -- 输出:索引为偶数的元素: [10, 30, 50] _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:filterIndexedTo(wc, function(index, word) return index % 2 ~= 0 and _objectWrappers:wrap(word):count() > 5 end) -- 输出:筛选后的单词: [android] _console:log("筛选后的单词: ", wc)
<?php $nc = $objectWrappers->wrap($iterables->mutableListOf()); $numbers = $objectWrappers->wrap($arrays->arrayOf($plugins->loadClass("java.lang.Long"), 10, 20, 30, 40, 50, 60)); // 筛选出索引为偶数的元素 $numbers->filterIndexedTo($nc, function ($index) { return $index % 2 == 0; }); // 输出:索引为偶数的元素: [10, 30, 50] $console->log("索引为偶数的元素: ", $nc); $wc = $objectWrappers->wrap($iterables->mutableListOf()); $words = $objectWrappers->wrap($arrays->arrayOf($plugins->loadClass("java.lang.String"), "hello", "world", "kotlin", "android")); // 筛选出索引为奇数且长度大于 5 的单词 $words->filterIndexedTo($wc, function ($index, $word) use ($objectWrappers) { return $index % 2 != 0 and $objectWrappers->wrap($word)->count() > 5; }); // 输出:筛选后的单词: [android] $console->log("筛选后的单词: ", $wc);
nc = _objectWrappers.wrap(_iterables.mutableListOf()) numbers = _objectWrappers.wrap(_arrays.arrayOf(_plugins.loadClass("java.lang.Long"), 10, 20, 30, 40, 50, 60)) # 筛选出索引为偶数的元素 numbers.filterIndexedTo(nc, lambda index, _: index % 2 == 0) # 输出:索引为偶数的元素: [10, 30, 50] _console.log("索引为偶数的元素: ", nc) wc = _objectWrappers.wrap(_iterables.mutableListOf()) words = _objectWrappers.wrap( _arrays.arrayOf(_plugins.loadClass("java.lang.String"), "hello", "world", "kotlin", "android")) # 筛选出索引为奇数且长度大于 5 的单词 words.filterIndexedTo(wc, lambda index, word: index % 2 != 0 and _objectWrappers.wrap(word).count() > 5) # 输出:筛选后的单词: [android] _console.log("筛选后的单词: ", wc)
# encoding: utf-8 nc = $objectWrappers.wrap($iterables.mutableListOf()) numbers = $objectWrappers.wrap($arrays.arrayOf($plugins.loadClass("java.lang.Long"), 10, 20, 30, 40, 50, 60)) # 筛选出索引为偶数的元素 numbers.filterIndexedTo(nc) { |index, _| index % 2 == 0 } # 输出:索引为偶数的元素: [10, 30, 50] $console.log("索引为偶数的元素: ", nc) wc = $objectWrappers.wrap($iterables.mutableListOf()) words = $objectWrappers.wrap($arrays.arrayOf($plugins.loadClass("java.lang.String"), "hello", "world", "kotlin", "android")) # 筛选出索引为奇数且长度大于 5 的单词 words.filterIndexedTo(wc) { |index, word| index % 2 != 0 && $objectWrappers.wrap(word).count() > 5 } # 输出:筛选后的单词: [android] $console.log("筛选后的单词: ", wc)
Last modified: 08 August 2025