The public static void fill(Object[] a,int fromIndex,int toIndex,Object val) in the Java API assigns the specified Object reference to each element in the specified range of the specified Object array. The filled range starts from the index fromIndex (including ) all the way to index toIndex (exclusive), if fromIndex==toIndex, the fill range is empty.
The specific method is as follows:
For example:
importjava.util.Arrays;publicclassMain{publicstaticvoidmain(String[]args){int[]a=newint[6];int[]b=newint[6];Arrays.fill(a,2);Arrays.fill(b ,2,4,6);for(inti=0;i<a.length;i++)System.out.print(a[i]+,);System.out.print(n);for(inti= 0;i<b.length;i++)System.out.print(b[i]+,);System.out.print(n);}}
The running results are as follows:
2,2,2,2,2,2,0,0,6,6,0,0,