Java Array class fill(byte[] a, byte val) example
Array class fill(byte[] a, byte val) method example
Array class fill(byte[] a, byte val)method example. This example shows you how to use fill(byte[] a, byte val)method.This method Assigns the specified byte value to each element of the specified array of bytes.
Here is the code:-
/**
* @Program that Assigns the specified byte value to each element of the
* specified array of bytes.
* fill2Array.java
* Author:-RoseIndia Team
* Date:-16-May-2008
*/
import java.util.*;
public class fill2Array {
public static void main(String[] args) {
//creating a byte array
byte b[]={1,2,3,4,5,6,5,4,3,2};
System.out.print("The original array is:-");
for(int i=0;i<b.length;i++)
//Display the byte array
System.out.print(b[i]);
System.out.println();
//Assigns the specified byte value to each element of the specified array
Arrays.fill(b,(byte)9);
System.out.print("The Changed array is:-");
for(int i=0;i<b.length;i++)
//Display the Changed byte array
System.out.print(b[i]);
}
} |
Output of the program:-
The original array is:-1234565432
The Changed array is:-9999999999 |
|