Arrays.fill(double[], double) in Java

Arrays.fill(double[], double): This method is available in java.util.Arrays class of Java.

Syntax:

void java.util.Arrays.fill(double[] a, double val)

This method takes two arguments one of type double array and the other of type double as its parameters. This method assigns the specified double value to each element of the specified array of doubles.

Parameters: Two parameters are required for this method.

a: the array to be filled.

val: the value to be stored in all elements of the array.

Returns: NA

Exceptions: NA

Approach

Java

import java.util.Arrays;

public class Arraysfilldouble {
    public static void main(String[] args) {

        double a[] = new double[5];

        double val = 10;

        Arrays.fill(a, val);

        System.out.println(Arrays.toString(a));
    }
}

Output:

[10.0, 10.0, 10.0, 10.0, 10.0]


No comments:

Post a Comment