Java Arrays fill方法-使用索引填充char


Java Arrays fill方法-使用索引填充char

package com.codingdict;

import java.util.Arrays;

public class ArrayDemo {
   public static void main(String[] args) {

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

      // let us print the values
      System.out.println("Actual values: ");
      for (char value : arr) {
         System.out.println("Value = " + value);
      }

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

      // let us print the values
      System.out.println("New values after using fill() method: ");
      for (char value : arr) {
         System.out.println("Value = " + value);
      }
   }
}