Java Array class fill(boolean[] a, int fromIndex, int toIndex, boolean val) example
Array class fill(boolean[] a, int fromIndex, int toIndex, boolean val) method example
Array class fill(boolean[] a, int fromIndex, int toIndex, boolean val) method example. This example shows you how to use fill(boolean[] a, int fromIndex, int toIndex, boolean val)method.This method Assigns the specified boolean value to each element of the specified range of the specified array of booleans.
Here is the code:-
/**
* @Program that Assigns the specified boolean value to each element of the
* specified range of the specified array of booleans.
* fill1Array.java
* Author:-RoseIndia Team
* Date:-16-May-2008
*/
import java.util.*;
public class fill1Array {
public static void main(String[] args) {
//Declaring a boolean array
boolean b[]={true,false,true,true,true,true,true,true,false,true,true};
//Assigns the specified boolean value to each element of the
// specified range
Arrays.fill(b,2,7,false);
for(int i=0;i<b.length;i++)
//Displays the changed array
System.out.println(b[i]);
}
} |
Output of the program:-
true
false
false
false
false
false
false
true
false
true
true |
|