ArrayFill

public final class org.apache.commons.lang3.ArrayFill[source]

Fills and returns arrays in the fluent style.

Since:

3.14.0

Methods

clear(byte[])

Fills and returns the given array, assigning 0 to each element of the array.

clear(char[])

Fills and returns the given array, assigning '\0' to each element of the array.

clear(char[], int, int)

Fills and returns the given array, assigning '\0' to each element of the array.

fill(boolean[], boolean)

Fills and returns the given array, assigning the given boolean value to each element of the array.

fill(byte[], byte)

Fills and returns the given array, assigning the given byte value to each element of the array.

fill(char[], char)

Fills and returns the given array, assigning the given char value to each element of the array.

fill(char[], int, int, char)

Fills and returns the given array, assigning the given char value to each element of the array.

fill(double[], double)

Fills and returns the given array, assigning the given double value to each element of the array.

fill(float[], float)

Fills and returns the given array, assigning the given float value to each element of the array.

fill(int[], int)

Fills and returns the given array, assigning the given int value to each element of the array.

fill(Object[], Object)

Fills and returns the given array, assigning the given T value to each element of the array.

fill(Object[], FailableIntFunction)

Fills and returns the given array, using the provided generator function to compute each element.

fill(long[], long)

Fills and returns the given array, assigning the given long value to each element of the array.

fill(short[], short)

Fills and returns the given array, assigning the given short value to each element of the array.

public static byte[] clear(byte[] a)[source]

Fills and returns the given array, assigning 0 to each element of the array.

ArrayFill.fill(a, (byte) 0);
Parameters:

a – The array to fill (may be null).

Returns:

The given array.

See also:
Since:

3.21.0

public static char[] clear(char[] a)[source]

Fills and returns the given array, assigning '\0' to each element of the array.

Equivalent to:

ArrayFill.fill(a, '\0'); // and not '0'!
Parameters:

a – The array to fill (may be null).

Returns:

The given array.

See also:
Since:

3.21.0

public static char[] clear(char[] a, int fromIndex, int toIndex)[source]

Fills and returns the given array, assigning '\0' to each element of the array.

Equivalent to:

ArrayFill.fill(a, fromIndex, toIndex, '\0'); // and not '0'!
Parameters:
  • a – The array to fill (may be null).

  • fromIndex – The index of the first element (inclusive) to be filled with '\0'.

  • toIndex – The index of the last element (exclusive) to be filled with '\0'.

Returns:

The given array.

See also:

Arrays#fill(char[], int, int, char)

Since:

3.21.0

public static boolean[] fill(boolean[] a, boolean val)[source]

Fills and returns the given array, assigning the given boolean value to each element of the array.

Parameters:
  • a – The array to fill (may be null).

  • val – The value to store in all elements of the array.

Returns:

The given array.

See also:

Arrays#fill(boolean[],boolean)

Since:

3.18.0

public static byte[] fill(byte[] a, byte val)[source]

Fills and returns the given array, assigning the given byte value to each element of the array.

Parameters:
  • a – The array to fill (may be null).

  • val – The value to store in all elements of the array.

Returns:

The given array.

See also:

Arrays#fill(byte[],byte)

public static char[] fill(char[] a, char val)[source]

Fills and returns the given array, assigning the given char value to each element of the array.

Parameters:
  • a – The array to fill (may be null).

  • val – The value to store in all elements of the array.

Returns:

The given array.

See also:

Arrays#fill(char[],char)

public static char[] fill(char[] a, int fromIndex, int toIndex, char val)[source]

Fills and returns the given array, assigning the given char value to each element of the array.

Parameters:
  • a – The array to fill (may be null).

  • val – The value to store in all elements of the array.

  • fromIndex – The index of the first element (inclusive) to be filled with the specified value.

  • toIndex – The index of the last element (exclusive) to be filled with the specified value.

Returns:

The given array.

See also:

Arrays#fill(char[], int, int, char)

Since:

3.21.0

public static double[] fill(double[] a, double val)[source]

Fills and returns the given array, assigning the given double value to each element of the array.

Parameters:
  • a – The array to fill (may be null).

  • val – The value to store in all elements of the array.

Returns:

The given array.

See also:

Arrays#fill(double[],double)

public static float[] fill(float[] a, float val)[source]

Fills and returns the given array, assigning the given float value to each element of the array.

Parameters:
  • a – The array to fill (may be null).

  • val – The value to store in all elements of the array.

Returns:

The given array.

See also:

Arrays#fill(float[],float)

public static int[] fill(int[] a, int val)[source]

Fills and returns the given array, assigning the given int value to each element of the array.

Parameters:
  • a – The array to fill (may be null).

  • val – The value to store in all elements of the array.

Returns:

The given array.

See also:

Arrays#fill(int[],int)

public static <T> T[] fill(T[] a, T val)[source]

Fills and returns the given array, assigning the given T value to each element of the array.

Type parameters:

<T> – The array type.

Parameters:
  • a – The array to fill (may be null).

  • val – The value to store in all elements of the array.

Returns:

The given array.

See also:

Arrays#fill(Object[],Object)

public static <T, E extends Throwable> T[] fill(T[] array, FailableIntFunction<? extends T, E> generator) throws E[source]

Fills and returns the given array, using the provided generator function to compute each element. Like Arrays#setAll(Object[], IntFunction) with exception support.

If the generator function throws an exception, it is relayed to the caller and the array is left in an indeterminate state.

If the input array or generator function is null, nothing happens.

Type parameters:
  • <T> – type of elements of the array.

  • <E> – The kind of thrown exception or error.

Parameters:
  • array – array to fill (may be null).

  • generator – A function accepting an index and producing the desired value for that position.

Returns:

The input array.

Throws:

E – Thrown by the given generator.

See also:

Arrays#setAll(Object[], IntFunction)

Since:

3.18.0

public static long[] fill(long[] a, long val)[source]

Fills and returns the given array, assigning the given long value to each element of the array.

Parameters:
  • a – The array to fill (may be null).

  • val – The value to store in all elements of the array.

Returns:

The given array.

See also:

Arrays#fill(long[],long)

public static short[] fill(short[] a, short val)[source]

Fills and returns the given array, assigning the given short value to each element of the array.

Parameters:
  • a – The array to fill (may be null).

  • val – The value to store in all elements of the array.

Returns:

The given array.

See also:

Arrays#fill(short[],short)