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

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

Syntax:

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

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

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 Arraysfilllong {
    public static void main(String[] args) {

        long a[] = new long[5];

        long val = 10;

        Arrays.fill(a, val);

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

Output:

[10, 10, 10, 10, 10]


No comments:

Post a Comment