Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
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
Advertisements
