In the following example, we fill elements into the array through the Array.fill(arrayname,value) method and the 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]); } }}
Above The output result of the code running is:
100 100 100 100 100 100 100 100 100 50 50 50
The above is the content of the Java example-array filling. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!