Home > Java > javaTutorial > body text

How to fill arrays.fill in java

WBOY
Release: 2023-05-05 16:10:07
forward
1373 people have browsed it

1. Concept

Array elements can be filled with the same value.

2. Syntax

public static void fill(int[] a, form, to, int var)
Copy after login

3. Parameters

a: Array

form: Replacement start Position (inclusive)

to: replacement end position (exclusive)

var: value to be replaced

4. Example

String[] a9 = new String[6];
Arrays.fill(a9, "Hello");
Arrays.fill(a9, 3, 5,"World");
Copy after login

The result is

a9[] = {Hello,Hello,Hello,World,World,Hello};
Copy after login

The first parameter refers to the array of operation, the second and third parameters refer to inserting the fourth parameter in a certain area of ​​the array, the second parameter refers to the starting element The subscript (including the subscript), the third parameter refers to the end subscript (excluding the subscript), note: Java's array subscript starts from 0.

The above is the detailed content of How to fill arrays.fill in java. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!