mapNotNull
val data = arrayOf("one", null, "three", "four", null)
// 将非空字符串转换为其长度, 非空字符串长度: [3, 5, 4]
data.mapNotNull {
it?.count()
}.forEach {
_console.log(it)
}
def data = $objectWrappers.wrap($arrays.arrayOf($plugins.loadClass("java.lang.String"), "one", null, "three", "four", null))
// 将非空字符串转换为其长度, 非空字符串长度: [3, 5, 4]
data.mapNotNull {
if (it != null) {
$objectWrappers.wrap(it).count()
}
}.forEach {
$console.log(it)
}
let data = $objectWrappers.wrap($arrays.arrayOf($plugins.loadClass("java.lang.String"), "one", null, "three", "four", null))
// 将非空字符串转换为其长度, 非空字符串长度: [3, 5, 4]
data.mapNotNull(it => {
if (it != null) {
return $objectWrappers.wrap(it).count()
} else {
return null
}
}).forEach((it) => {
$console.log(it)
})
local data = _objectWrappers:wrap(_arrays:arrayOf(_plugins:loadClass("java.lang.String"), "one", nil, "three", "four", nil))
-- 将非空字符串转换为其长度, 非空字符串长度: [3, 5, 4]
data:mapNotNull(function(it)
if (it ~= nil) then
return _objectWrappers:wrap(it):count()
else
return nil
end
end):forEach(function(it)
_console:log(it)
end)
<?php
$data = $objectWrappers->wrap($arrays->arrayOf($plugins->loadClass("java.lang.String"), "one", null, "three", "four", null));
// 将非空字符串转换为其长度, 非空字符串长度: [3, 5, 4]
$data->mapNotNull(function ($it) use ($objectWrappers) {
if ($it != null) return $objectWrappers->wrap($it)->count(); else return null;
})->forEach(function ($it) use ($console) {
$console->log($it);
});
data = _objectWrappers.wrap(_arrays.arrayOf(_plugins.loadClass("java.lang.String"), "one", None, "three", "four", None))
# 将非空字符串转换为其长度, 非空字符串长度: [3, 5, 4]
data.mapNotNull(lambda it: _objectWrappers.wrap(it).count() if it != None else None).forEach(
lambda it: _console.log(it))
# encoding: utf-8
data = $objectWrappers.wrap($arrays.arrayOf($plugins.loadClass("java.lang.String"), "one", nil, "three", "four", nil))
# 将非空字符串转换为其长度, 非空字符串长度: [3, 5, 4]
data.mapNotNull { |it|
if it != nil then
$objectWrappers.wrap(it).count()
else
nil
end
}.forEach { |it|
$console.log(it)
}
Last modified: 09 September 2025