Java Array class fill(long[] a, int fromIndex, int toIndex, long val) example code
Array class fill(long[] a, int fromIndex, int toIndex, long val) method example
Array class fill(long[] a, int fromIndex, int toIndex, long val) method example. This example shows you how to use fill(long[] a, int fromIndex, int toIndex, long val) method.This method Assigns the specified long value to each element of the specified range of the specified array of longs
Here is the code:-
/**
* @Program that Assigns the specified long value to each element of the
* specified range of the specified array of longs
* fill12Array.java
* Author:-RoseIndia Team
* Date:-16-May-2008
*/
import java.util.*;
public class fill12Array {
public static void main(String[] args) {
//creating a long array
long b[] = {12,12,34,56,78,90,98};
System.out.print("The original array is:-");
for (int i = 0; i < b.length; i++) //Display the long array
{
System.out.print("\t"+b[i]);
}
System.out.println();
//Assigns the specified long value to each element of the
//* specified range of the specified array of longs
Arrays.fill(b,0,4,2);
System.out.print("The Changed array is:-");
for (int i = 0; i < b.length; i++)
//Display the Changed long array
{
System.out.print("\t"+b[i]);
}
}
} |
Output of the program:-
The original array is:- 12 12 34 56 78 90 98
The Changed array is:- 2 2 2 2 78 90 98 |
|