Filling an array with Arrays.fill method - Java Language Basics

Java examples for Language Basics:Array

Introduction

For example, here's a routine that creates an array of integers and initializes each element to 100:

Demo Code

import java.util.Arrays;

public class Main {

  public static void main(String[] args) {
    int[] ran = new int[10];
    Arrays.fill(ran, 10);/*from   w ww  .  j a v a2  s.  c o  m*/
    System.out.println(Arrays.toString(ran));
  }

}

Related Tutorials