mapIndexedNotNull
val data = arrayOf("one", null, "three", "four", null)
// 将非空字符串转换为其长度,并添加索引信息, 带索引的非空字符串长度: [0_3, 2_5, 3_4]
data.mapIndexedNotNull { index, word ->
if (word != null) {
"$index" + "_" + word.length
} else {
null
}
}.forEach {
_console.log(it)
}
def data = $objectWrappers.wrap($arrays.arrayOf($plugins.loadClass("java.lang.String"), "one", null, "three", "four", null))
// 将非空字符串转换为其长度,并添加索引信息, 带索引的非空字符串长度: [0_3, 2_5, 3_4]
data.mapIndexedNotNull { index, word ->
if (word != null) {
index + "_" + $objectWrappers.wrap(word).count()
}
}.forEach {
$console.log(it)
}
let data = $objectWrappers.wrap($arrays.arrayOf($plugins.loadClass("java.lang.String"), "one", null, "three", "four", null))
// 将非空字符串转换为其长度,并添加索引信息, 带索引的非空字符串长度: [0_3, 2_5, 3_4]
data.mapIndexedNotNull((index, word) => {
if (word != null) {
return index + "_" + $objectWrappers.wrap(word).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))
-- 将非空字符串转换为其长度,并添加索引信息, 带索引的非空字符串长度: [0_3, 2_5, 3_4]
data:mapIndexedNotNull(function(index, word)
if (word ~= nil) then
return index .. "_" .. _objectWrappers:wrap(word):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));
// 将非空字符串转换为其长度,并添加索引信息, 带索引的非空字符串长度: [0_3, 2_5, 3_4]
$data->mapIndexedNotNull(function ($index, $word) use ($objectWrappers) {
if ($word != null) return $index . "_" . $objectWrappers->wrap($word)->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))
# 将非空字符串转换为其长度,并添加索引信息, 带索引的非空字符串长度: [0_3, 2_5, 3_4]
data.mapIndexedNotNull(
lambda index, word: str(index) + "_" + str(_objectWrappers.wrap(word).count()) if word != 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))
# 将非空字符串转换为其长度,并添加索引信息, 带索引的非空字符串长度: [0_3, 2_5, 3_4]
data.mapIndexedNotNull { |index, word|
if word != nil then
index.to_s + "_" + $objectWrappers.wrap(word).count().to_s
else
nil
end
}.forEach { |it|
$console.log(it)
}
Last modified: 09 September 2025