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 4396 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

Leave a Comment


x

You might be Interested in these Posts

How to Create an Empty array without defining the size in C# ?

When we create an array in C# , we tend to define the size of the array as shown below. String[] st...

Video - Angular Router - Brian Ford

Video - Angular Router - Brian Ford http://www.youtube.com/watch?v=sfV0ApyN5fM ...

Video - An Angular2 Todo App: First look at App Development in Angular2

In this screencast , David East , one of the core contributor of the Angular provides a glimpse of A...