集册 Java实例教程 填充数组中的元素

填充数组中的元素

欢马劈雪     最近更新时间:2020-01-02 10:19:05

458
填充数组中的元素
//n o w    j a v a  . c o m 提供

import java.util.Arrays;


public class Main {

  public static void main(String[] argv) {

    boolean[] booleanArr = new boolean[10];

    boolean booleanFillValue = false;

    Arrays.fill(booleanArr, booleanFillValue);


    byte[] byteArr = new byte[10];

    byte byteFillValue = (byte) 0xFF;

    Arrays.fill(byteArr, byteFillValue);


    char[] charArr = new char[10];

    char charFillValue = 0xFF;

    Arrays.fill(charArr, charFillValue);


    short[] shortArr = new short[10];

    short shortFillValue = 0xFF;

    Arrays.fill(shortArr, shortFillValue);
/*from 时 代 J a v a*/

    int[] intArr = new int[10];

    int intFillValue = -1;

    Arrays.fill(intArr, intFillValue);


    long[] longArr = new long[10];

    long longFillValue = -1;

    Arrays.fill(longArr, longFillValue);


    float[] floatArr = new float[10];

    float floatFillValue = -1;

    Arrays.fill(floatArr, floatFillValue);


    double[] doubleArr = new double[10];

    double doubleFillValue = -1;

    Arrays.fill(doubleArr, doubleFillValue);

    String[] StringArr = new String[1];

    String StringFillValue = "";

    Arrays.fill(StringArr, StringFillValue);

    // Fill elements 0, 1, 2, and 3; the end index is exclusive

    int startIndex = 0;

    int endIndex = 4;


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

    Arrays.fill(byteArr, startIndex, endIndex, byteFillValue);

    Arrays.fill(char
展开阅读全文