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

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

Syntax:

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

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

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

        short a[] = new short[5];

        short val = 10;

        Arrays.fill(a, val);

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

Output:

[10, 10, 10, 10, 10]


No comments:

Post a Comment