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