Class ArrayFill
java.lang.Object
org.apache.commons.lang3.ArrayFill
-
Method Summary
Modifier and TypeMethodDescriptionstatic byte[]clear(byte[] a) Fills and returns the given array, assigning0to each element of the array.static char[]clear(char[] a) Fills and returns the given array, assigning'\0'to each element of the array.static char[]clear(char[] a, int fromIndex, int toIndex) Fills and returns the given array, assigning'\0'to each element of the array.static boolean[]fill(boolean[] a, boolean val) Fills and returns the given array, assigning the givenbooleanvalue to each element of the array.static byte[]fill(byte[] a, byte val) Fills and returns the given array, assigning the givenbytevalue to each element of the array.static char[]fill(char[] a, char val) Fills and returns the given array, assigning the givencharvalue to each element of the array.static char[]fill(char[] a, int fromIndex, int toIndex, char val) Fills and returns the given array, assigning the givencharvalue to each element of the array.static double[]fill(double[] a, double val) Fills and returns the given array, assigning the givendoublevalue to each element of the array.static float[]fill(float[] a, float val) Fills and returns the given array, assigning the givenfloatvalue to each element of the array.static int[]fill(int[] a, int val) Fills and returns the given array, assigning the givenintvalue to each element of the array.static long[]fill(long[] a, long val) Fills and returns the given array, assigning the givenlongvalue to each element of the array.static short[]fill(short[] a, short val) Fills and returns the given array, assigning the givenshortvalue to each element of the array.static <T, E extends Throwable>
T[]fill(T[] array, FailableIntFunction<? extends T, E> generator) Fills and returns the given array, using the provided generator function to compute each element.static <T> T[]fill(T[] a, T val) Fills and returns the given array, assigning the givenTvalue to each element of the array.
-
Method Details
-
clear
Fills and returns the given array, assigning0to each element of the array.ArrayFill.fill(a, (byte) 0);
- Parameters:
a- The array to fill (may be null).- Returns:
- The given array.
- Since:
- 3.21.0
- See Also:
-
clear
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.
- Since:
- 3.21.0
- See Also:
-
clear
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.
- Since:
- 3.21.0
- See Also:
-
fill
Fills and returns the given array, assigning the givenbooleanvalue 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.
- Since:
- 3.18.0
- See Also:
-
fill
Fills and returns the given array, assigning the givenbytevalue 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:
-
fill
Fills and returns the given array, assigning the givencharvalue 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:
-
fill
Fills and returns the given array, assigning the givencharvalue to each element of the array.- Parameters:
a- The array to fill (may be null).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.val- The value to store in all elements of the array.- Returns:
- The given array.
- Since:
- 3.21.0
- See Also:
-
fill
Fills and returns the given array, assigning the givendoublevalue 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:
-
fill
Fills and returns the given array, assigning the givenfloatvalue 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:
-
fill
Fills and returns the given array, assigning the givenintvalue 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:
-
fill
Fills and returns the given array, assigning the givenlongvalue 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:
-
fill
Fills and returns the given array, assigning the givenshortvalue 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:
-
fill
public static <T, E extends Throwable> T[] fill(T[] array, FailableIntFunction<? extends T, E> generator) throws E Fills and returns the given array, using the provided generator function to compute each element. LikeArrays.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 givengenerator.- Since:
- 3.18.0
- See Also:
-
fill
Fills and returns the given array, assigning the givenTvalue 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:
-