Example usage for java.util Arrays fill

List of usage examples for java.util Arrays fill

Introduction

In this page you can find the example usage for java.util Arrays fill.

Prototype

public static void fill(Object[] a, int fromIndex, int toIndex, Object val) 

Source Link

Document

Assigns the specified Object reference to each element of the specified range of the specified array of Objects.

Usage

From source file:Main.java

public static void main(String[] args) {

    float arr[] = new float[] { 1f, 2f, 3f, 4f, 5f };

    System.out.println(Arrays.toString(arr));

    // using fill for placing 12 from index 1 to 3
    Arrays.fill(arr, 1, 3, 12f);

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

From source file:Main.java

public static void main(String[] args) {

    // initializing int array
    int arr[] = new int[] { 1, 2, 3, 4, 5 };

    System.out.println(Arrays.toString(arr));

    // using fill for placing 18 from index 2 to 4
    Arrays.fill(arr, 2, 4, 18);

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

From source file:Main.java

public static void main(String[] args) {

    // initializing long array
    long arr[] = new long[] { 1, 5, 9, 3, 7 };

    System.out.println(Arrays.toString(arr));

    // using fill for placing 10 from index 1 to 3
    Arrays.fill(arr, 1, 3, 10);

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

From source file:Main.java

public static void main(String[] args) {

    // initializing short array
    short arr[] = new short[] { 2, 3, 13, 23, 97 };

    System.out.println(Arrays.toString(arr));

    // using fill for placing 19 from index 1 to 3
    Arrays.fill(arr, 1, 3, (short) 19);

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

From source file:Main.java

public static void main(String[] args) {

    // initializing char array
    char arr[] = new char[] { 'a', 'b', 'c', 'd', 'e', 'f' };

    System.out.println(Arrays.toString(arr));

    // using fill for placing z from index 2 to 4
    Arrays.fill(arr, 2, 4, 'z');

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

From source file:Main.java

public static void main(String[] args) {

    // initializing double array
    double arr[] = new double[] { 1.2, 5.6, 3.4, 2.3, 6.7 };

    System.out.println(Arrays.toString(arr));

    // using fill for placing 1.2 from index 1 to 3
    Arrays.fill(arr, 1, 3, 1.2);

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

From source file:Main.java

public static void main(String[] args) {

    // initializing object array
    Object arr[] = new Object[] { 1.2, 5.6, 3.4, 2.3, 6.7 };

    System.out.println(Arrays.toString(arr));

    // using fill for placing 12.2 from index 1 to 3
    Arrays.fill(arr, 1, 3, 12.2);

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

From source file:Main.java

public static void main(String[] args) {

    // initializing boolean array
    boolean arr[] = new boolean[] { true, true, true, true, true };

    System.out.println(Arrays.toString(arr));

    // using fill for placing false from index 1 to 4
    Arrays.fill(arr, 1, 4, false);

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

From source file:Main.java

public static void main(String[] args) {

    // initializing byte array
    byte arr[] = new byte[] { 1, 6, 3, 2, 9 };

    System.out.println(Arrays.toString(arr));

    // using fill for placing 64 from index 2 to 4
    // converting int to byte
    Arrays.fill(arr, 2, 4, (byte) 64);

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

From source file:Main.java

  public static void main(String[] argv) throws Exception {
  int startIndex = 0;
  int endIndex = 4;

  boolean[] booleanArr = new boolean[10];
  boolean booleanFillValue = true;

  Arrays.fill(booleanArr, startIndex, endIndex, booleanFillValue);

}