fill
val numbers = arrayOfNulls<Int>(5)
// 使用值 10 填充数组的索引0-3所有元素
numbers.fill(10, 0, 3)
// 填充后的数组: [10, 10, 10, null, null]
numbers.forEachIndexed { index, element ->
_console.log(index, element)
}
// 创建一个大小为 5 的字符串数组,并使用 "hello" 填充
val strings = arrayOfNulls<String>(5)
strings.fill("hello", 0, 3)
// 字符串数组: [hello, hello, hello, null, null]
strings.forEachIndexed { index, element ->
_console.log(index, element)
}
def numbers = $objectWrappers.wrap($arrays.newArray($plugins.loadClass("java.lang.Integer"), 5))
// 使用值 10 填充数组的索引0-3所有元素
numbers.fill(10, 0, 3)
// 填充后的数组: [10, 10, 10, null, null]
numbers.forEachIndexed { index, element ->
$console.log(index, element)
}
// 创建一个大小为 5 的字符串数组,并使用 "hello" 填充
def strings = $objectWrappers.wrap($arrays.newArray($plugins.loadClass("java.lang.String"), 5))
strings.fill("hello", 0, 3)
// 字符串数组: [hello, hello, hello, null, null]
strings.forEachIndexed { index, element ->
$console.log(index, element)
}
let numbers = $objectWrappers.wrap($arrays.newArray($plugins.loadClass("java.lang.Integer"), 5))
// 使用值 10 填充数组的索引0-3所有元素
numbers.fill(10, 0, 3)
// 填充后的数组: [10, 10, 10, null, null]
numbers.forEachIndexed((index, element) => {
$console.log(index, element)
})
// 创建一个大小为 5 的字符串数组,并使用 "hello" 填充
let strings = $objectWrappers.wrap($arrays.newArray($plugins.loadClass("java.lang.String"), 5))
strings.fill("hello", 0, 3)
// 字符串数组: [hello, hello, hello, null, null]
strings.forEachIndexed((index, element) => {
$console.log(index, element)
})
local numbers = _objectWrappers:wrap(_arrays:newArray(_plugins:loadClass("java.lang.Integer"), 5))
-- 使用值 10 填充数组的索引0-3所有元素
numbers:fill(10, 0, 3)
-- 填充后的数组: [10, 10, 10, nil, nil]
numbers:forEachIndexed(function(index, element)
_console:log(index, element)
end)
-- 创建一个大小为 5 的字符串数组,并使用 "hello" 填充
local strings = _objectWrappers:wrap(_arrays:newArray(_plugins:loadClass("java.lang.String"), 5))
strings:fill("hello", 0, 3)
-- 字符串数组: [hello, hello, hello, nil, nil]
strings:forEachIndexed(function(index, element)
_console:log(index, element)
end)
<?php
$numbers = $objectWrappers->wrap($arrays->newArray($plugins->loadClass("java.lang.Long"), 5));
// 使用值 10 填充数组的索引0-3所有元素
$numbers->fill(10, 0, 3);
// 填充后的数组: [10, 10, 10, null, null]
$numbers->forEachIndexed(function ($index, $element) use ($console) {
$console->log($index, $element);
});
// 创建一个大小为 5 的字符串数组,并使用 "hello" 填充
$strings = $objectWrappers->wrap($arrays->newArray($plugins->loadClass("java.lang.String"), 5));
$strings->fill("hello", 0, 3);
// 字符串数组: [hello, hello, hello, null, null]
$strings->forEachIndexed(function ($index, $element) use ($console) {
$console->log($index, $element);
});
numbers = _objectWrappers.wrap(_arrays.newArray(_plugins.loadClass("java.lang.Long"), 5))
# 使用值 10 填充数组的索引0-3所有元素
numbers.fill(10, 0, 3)
# 填充后的数组: [10, 10, 10, None, None]
numbers.forEachIndexed(lambda index, element: _console.log(index, element))
# 创建一个大小为 5 的字符串数组,并使用 "hello" 填充
strings = _objectWrappers.wrap(_arrays.newArray(_plugins.loadClass("java.lang.String"), 5))
strings.fill("hello", 0, 3)
# 字符串数组: [hello, hello, hello, None, None]
strings.forEachIndexed(lambda index, element: _console.log(index, element))
# encoding: utf-8
numbers = $objectWrappers.wrap($arrays.newArray($plugins.loadClass("java.lang.Long"), 5))
# 使用值 10 填充数组的索引0-3所有元素
numbers.fill(10, 0, 3)
# 填充后的数组: [10, 10, 10, nil, nil]
numbers.forEachIndexed { |index, element|
$console.log(index, element)
}
# 创建一个大小为 5 的字符串数组,并使用 "hello" 填充
strings = $objectWrappers.wrap($arrays.newArray($plugins.loadClass("java.lang.String"), 5))
strings.fill("hello", 0, 3)
# 字符串数组: [hello, hello, hello, nil, nil]
strings.forEachIndexed { |index, element|
$console.log(index, element)
}
Last modified: 08 August 2025