Java Array class fill(char[] a, int fromIndex, int toIndex, char val) example
Array class fill(char[] a, int fromIndex, int toIndex, char val)method example
Array class fill(char[] a, int fromIndex, int toIndex, char val) method example. This example shows you how to use fill(char[] a, int fromIndex, int toIndex, char val) method.This method Assigns the specified char value to each element of the specified range of the specified array of chars.
Here is the code:-
->
/**
* @Program that Assigns the specified char value to each element of the
* specified range of the specified array of chars.
* fill5Array.java
* Author:-RoseIndia Team
* Date:-16-May-2008
*/
import java.util.*;
public class fill5Array {
public static void main(String[] args) {
//creating a Character array
char b[] = {'a', 'b', 'c', 'd'};
System.out.print("The original array is:-");
for (int i = 0; i < b.length; i++) //Display the character array
{
System.out.print(b[i]);
}
System.out.println();
//Assigns the specified char value to each element of the specified range of
//the specified array of chars.
Arrays.fill(b, 0, 4, 'A');
System.out.print("The Changed array is:-");
for (int i = 0; i < b.length; i++) //Display the Changed character array
{
System.out.print(b[i]);
}
}
} |
Output of the program:-
The original array is:-abcd
The Changed array is:-AAAA |
|