Home > Java > javaTutorial > body text

[Java Example] Array filling

黄舟
Release: 2017-02-07 10:53:53
Original
1440 people have browsed it

The following example:

We fill elements into the array through the Array.fill(arrayname,value) method and Array.fill(arrayname, starting index, ending index, value) method of the Java Util class:

/*
 author by w3cschool.cc
 文件名:FillTest.java
 */import java.util.*;public class FillTest {
public static void main(String args[]) {
  int array[] = new int[6];
 Arrays.fill(array, 100);
for (int i=0, n=array.length; i < n; i++) {
   System.out.println(array[i]);
 }
 System.out.println();
 Arrays.fill(array, 3, 6, 50);
  for (int i=0, n=array.length; i< n; i++) {
   System.out.println(array[i]);
   }
}}
Copy after login

The output result of running the above code is:

100
100
100
100
100
100
100
100
100
50
50
50
Copy after login

The above is the content of the [Java instance] array filling. For more related content, please pay attention to the PHP Chinese website (m.sbmmt.com)!


Related labels:
source:php.cn
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!