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