What does the method fill(obj[], object val) do?
The fill(Object[] a, Object val) method of the java.util.Arrays class assigns the specified Object reference to each element of the specified array of Objects.
Example
import java.util.Arrays;
public class ArrayDemo {
public static void main(String[] args) {
Object arr[] = new Object[] {10.5, 5.6, 4.7, 2.9, 9.7};
System.out.println("Actual values: ");
for (Object value : arr) {
System.out.println("Value = " + value);
}
Arrays.fill(arr, 12.2);
System.out.println("New values after using fill() method: ");
for (Object value : arr) {
System.out.println("Value = " + value);
}
}
}
Output
Actual values:
Value = 10.5
Value = 5.6
Value = 4.7
Value = 2.9
Value = 9.7
New values after using fill() method:
Value = 12.2
Value = 12.2
Value = 12.2
Value = 12.2
Value = 12.2
Published on 24-Apr-2018 12:13:45
- Related Questions & Answers
- What does the method fill(obj[], int fromIndex, int toIndex, int val) do in java?
- What does the method fill(int[], int val) do in java?
- What does the method fill(int[], int fromIndex, int toIndex, int val) do in java?
- What does the method equals(obj[] a1, obj[] a2) do in java?
- What does the method lastIndexOf(obj o) do in java?
- What does the method remove(obj o) do in java?
- What does the method hashCode(obj[] a) do in java?
- What does the method sort(obj[] a) do in java?
- What does the method toString(obj[] a) do in java?
- What does the method addElement(E obj) do in java?
- What does the method contains(obj o) do in java?
- What does the method indexOf(obj o) do in java?
- What does the method set(int, obj o) do in java?
- What does the method sort(obj[] a, int fromIndex, int toIndex) do in java?
- What does the method push(Object item) do in java?