Java Array Fill fillArray(byte[] btArray, byte[] btValue, int iStartPosition, int iLength, byte btAlternateValue, int iAlign)

Here you can find the source of fillArray(byte[] btArray, byte[] btValue, int iStartPosition, int iLength, byte btAlternateValue, int iAlign)

Description

fill Array

License

Apache License

Declaration

public static void fillArray(byte[] btArray, byte[] btValue, int iStartPosition, int iLength,
            byte btAlternateValue, int iAlign) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.*;

public class Main {
    public static final int ALIGN_RIGHT = 1;

    public static void fillArray(byte[] btArray, byte[] btValue, int iStartPosition, int iLength,
            byte btAlternateValue, int iAlign) {
        int iFillLength = btValue.length;
        if (iFillLength > iLength)
            iFillLength = iLength;//from  w w w .j a v  a2 s. co  m
        int iAlternateLength = iLength - iFillLength;
        if (iAlign == ALIGN_RIGHT) {
            int iDataPosition = iStartPosition + iAlternateLength;
            Arrays.fill(btArray, iStartPosition, iDataPosition, btAlternateValue);
            System.arraycopy(btValue, 0, btArray, iDataPosition, iFillLength);
        } else {
            int iAlternatePosition = iFillLength + iStartPosition;
            System.arraycopy(btValue, 0, btArray, iStartPosition, iFillLength);
            Arrays.fill(btArray, iAlternatePosition, iAlternatePosition + iAlternateLength, btAlternateValue);
        }
    }

    public static void fillArray(byte[] btArray, byte btValue, int iStartPosition, int iLength) {
        for (int iIndex = 0; iIndex < iLength; iIndex++)
            btArray[iIndex + iStartPosition] = btValue;
    }
}

Related

  1. fill(final T[] array, final int size)
  2. fill(final T[] array, final T value)
  3. fill(int[][] array, int value)
  4. fill(String[] ary, String value)
  5. fill(T[][][] arr, T val)
  6. fillArray(byte[] data)
  7. fillArray(char[] array, int offset, char value)
  8. fillArray(double[][][] array, double[] value, int rows, int columns)
  9. fillArray(final float[] array, final float value)