How to fill an array with default values in Java ?

Published on July 5, 2015 by abundantcode

Filed under Java

Last modified July 5, 2015

Print this page

rate 1 star rate 2 star rate 3 star rate 4 star rate 5 star
Your rating: none, Average: 4 (1 votes)

This article have been viewed 3331 times

If you want to fill an array with default values in Java , you can use the Arrays.fill method to do it . The Arrays.fill method lets the developers fill the empty array with the default values.

How to fill an array with default values in Java ?

Below is an example of the usage of the Arrays.fill method in java .

package com.abundantcode;
import java.util.Arrays;
public class Main {

    public static void main(String[] args)
    {
        String[] input = new String[5];
        Arrays.fill(input,"Abundantcode.com's Java Lab programs");
        for(String item:input)
            System.out.println(item);
    }
}

image

If you enjoyed this post, please consider leaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.

Leave a Comment


x

You might be Interested in these Posts

C Program to display Inverted half-pyramid using *

Problem Write a program in C to print Inverted half-pyramid using * as shown below.The program shou...

How to use array Rank in C# ?

In C# , the Rank property of the array is is used to get the rank of the array. In simple terms , ra...

How to get the Number of Elements in an MultiDimensional Array in C# ?

In one of the previous articles , we demonstrated the usage of the Length property of the array in C...