Class ArraysExt
Arrays utility class.
 Some worthy methods are:
 - The resizemethods, which are very similar to theArrays.copyOf(…)methods except that they acceptnullarrays and do not copy anything if the given array already has the requested length.
- The insertandremovemethods for adding and removing elements in the middle of an array.
- The isSortedmethods for verifying if an array is sorted, strictly or not.
Handling of null values
Many (but not all) methods in this class are tolerant to null parameter values, sometimes under certain conditions. See the method javadoc for details.All methods in this class are tolerant to null elements in arrays. Null and NaN elements are ignored.
Performance consideration
The methods listed below are provided as convenience for casual use on small arrays. For large arrays or for frequent use, consider using the Java collection framework instead.| Method | Alternative | 
|---|---|
| resize(Object[], int) | ArrayList | 
| append(Object[], Object) | ArrayList | 
| insert(Object[], int, Object[], int, int) | LinkedList | 
| remove(Object[], int, int) | LinkedList | 
| intersects(Object[], Object[]) | HashSet | 
| contains(Object[], Object) | HashSet | 
| containsIdentity(Object[], Object) | IdentityHashMap | 
- Since:
- 0.3
- See Also:
Defined in the sis-utility module
- 
Field SummaryFieldsModifier and TypeFieldDescriptionstatic final boolean[]An empty array ofbooleanprimitive type.static final byte[]An empty array ofbyteprimitive type.static final char[]An empty array ofcharprimitive type.static final double[]An empty array ofdoubleprimitive type.static final float[]An empty array offloatprimitive type.static final int[]An empty array ofintprimitive type.static final long[]An empty array oflongprimitive type.static final short[]An empty array ofshortprimitive type.
- 
Method SummaryModifier and TypeMethodDescriptionstatic booleanallEquals(double[] array, double value) Returnstrueif all values in the specified array are equal to the specified value, which may beDouble.NaN.static booleanallEquals(float[] array, float value) Returnstrueif all values in the specified array are equal to the specified value, which may beFloat.NaN.static booleanallEquals(int[] array, int value) Returnstrueif all values in the specified array are equal to the specified value.static booleanallEquals(Object[] array, Object value) Returnstrueif all values in the specified array are equal to the specified value, which may benull.static <T> T[]append(T[] array, T element) Returns a copy of the given array with a single element appended at the end.static <T> T[]concatenate(T[]... arrays) Returns the concatenation of all given arrays.static booleanReturnstrueif the specified array contains the specified value.static booleancontainsIdentity(Object[] array, Object value) Returnstrueif the specified array contains the specified reference.static booleancontainsIgnoreCase(String[] array, String value) Returnstrueif the specified array contains the specified value, ignoring case.static float[]copyAsFloats(double[] data) Returns a copy of the given array where each value has been casted to thefloattype.static float[]copyAsFloatsIfLossless(double[] data) Returns a copy of the given array where each value has been casted to thefloattype, but only if all casts are lossless.static long[]copyAsLongs(int[] data) Returns a copy of the given array where each value has been casted to thelongtype.static booleanhasNaN(double[] array) Returnstrueif the specified array contains at least oneNaNvalue.static booleanhasNaN(float[] array) Returnstrueif the specified array contains at least oneNaNvalue.static boolean[]insert(boolean[] src, int srcOff, boolean[] dst, int dstOff, int length) Returns an array containing the same elements than the given array, with the content of another array inserted at the given index.static boolean[]insert(boolean[] array, int first, int length) Returns an array containing the same elements than the given array, with additional "spaces" in the given range.static byte[]insert(byte[] src, int srcOff, byte[] dst, int dstOff, int length) Returns an array containing the same elements than the given array, with the content of another array inserted at the given index.static byte[]insert(byte[] array, int first, int length) Returns an array containing the same elements than the given array, with additional "spaces" in the given range.static char[]insert(char[] src, int srcOff, char[] dst, int dstOff, int length) Returns an array containing the same elements than the given array, with the content of another array inserted at the given index.static char[]insert(char[] array, int first, int length) Returns an array containing the same elements than the given array, with additional "spaces" in the given range.static double[]insert(double[] src, int srcOff, double[] dst, int dstOff, int length) Returns an array containing the same elements than the given array, with the content of another array inserted at the given index.static double[]insert(double[] array, int first, int length) Returns an array containing the same elements than the given array, with additional "spaces" in the given range.static float[]insert(float[] src, int srcOff, float[] dst, int dstOff, int length) Returns an array containing the same elements than the given array, with the content of another array inserted at the given index.static float[]insert(float[] array, int first, int length) Returns an array containing the same elements than the given array, with additional "spaces" in the given range.static int[]insert(int[] array, int first, int length) Returns an array containing the same elements than the given array, with additional "spaces" in the given range.static int[]insert(int[] src, int srcOff, int[] dst, int dstOff, int length) Returns an array containing the same elements than the given array, with the content of another array inserted at the given index.static long[]insert(long[] array, int first, int length) Returns an array containing the same elements than the given array, with additional "spaces" in the given range.static long[]insert(long[] src, int srcOff, long[] dst, int dstOff, int length) Returns an array containing the same elements than the given array, with the content of another array inserted at the given index.static short[]insert(short[] array, int first, int length) Returns an array containing the same elements than the given array, with additional "spaces" in the given range.static short[]insert(short[] src, int srcOff, short[] dst, int dstOff, int length) Returns an array containing the same elements than the given array, with the content of another array inserted at the given index.static <E> E[]insert(E[] array, int first, int length) Returns an array containing the same elements than the given array, with additional "spaces" in the given range.static <E> E[]insert(E[] src, int srcOff, E[] dst, int dstOff, int length) Returns an array containing the same elements than the given array, with the content of another array inserted at the given index.static booleanintersects(Object[] array1, Object[] array2) Returnstrueif at least one element in the first array is equals to an element in the second array.static booleanisRange(int start, int[] array) Returnstrueif the given array is a finite arithmetic progression starting at the given value and having a common difference of 1.static booleanisSinglePrecision(double... values) Returnstrueif every values in the givendoublearray could be casted to thefloattype without data lost.static booleanisSorted(byte[] array, boolean strict) Returnstrueif all elements in the specified array are in increasing order.static booleanisSorted(char[] array, boolean strict) Returnstrueif all elements in the specified array are in increasing order.static booleanisSorted(double[] array, boolean strict) Returnstrueif all elements in the specified array are in increasing order.static booleanisSorted(float[] array, boolean strict) Returnstrueif all elements in the specified array are in increasing order.static booleanisSorted(int[] array, boolean strict) Returnstrueif all elements in the specified array are in increasing order.static booleanisSorted(long[] array, boolean strict) Returnstrueif all elements in the specified array are in increasing order.static booleanisSorted(short[] array, boolean strict) Returnstrueif all elements in the specified array are in increasing order.static <E extends Comparable<? super E>>
 booleanisSorted(E[] array, boolean strict) Returnstrueif all elements in the specified array are in increasing order.static <E> booleanisSorted(E[] array, Comparator<? super E> comparator, boolean strict) Returnstrueif all elements in the specified array are in increasing order.static int[]range(int start, int end) Returns the ordered values in the range fromstartinclusive toendexclusive.static boolean[]remove(boolean[] array, int first, int length) Returns an array containing the same elements than the given array except for the given range.static byte[]remove(byte[] array, int first, int length) Returns an array containing the same elements than the given array except for the given range.static char[]remove(char[] array, int first, int length) Returns an array containing the same elements than the given array except for the given range.static double[]remove(double[] array, int first, int length) Returns an array containing the same elements than the given array except for the given range.static float[]remove(float[] array, int first, int length) Returns an array containing the same elements than the given array except for the given range.static int[]remove(int[] array, int first, int length) Returns an array containing the same elements than the given array except for the given range.static long[]remove(long[] array, int first, int length) Returns an array containing the same elements than the given array except for the given range.static short[]remove(short[] array, int first, int length) Returns an array containing the same elements than the given array except for the given range.static <E> E[]remove(E[] array, int first, int length) Returns an array containing the same elements than the given array except for the given range.static intremoveDuplicated(Object[] array) Removes the duplicated elements in the given array.static voidreplace(double[] array, double search, double replacement) Replaces all occurrences of the given value by the given replacement.static voidreplace(float[] array, float search, float replacement) Replaces all occurrences of the given value by the given replacement.static boolean[]resize(boolean[] array, int length) Returns an array containing the same elements as the givenarraybut specifiedlength, truncating or padding withfalseif necessary.static byte[]resize(byte[] array, int length) Returns an array containing the same elements as the givenarraybut specifiedlength, truncating or padding with zeros if necessary.static char[]resize(char[] array, int length) Returns an array containing the same elements as the givenarraybut specifiedlength, truncating or padding with zeros if necessary.static double[]resize(double[] array, int length) Returns an array containing the same elements as the givenarraybut specifiedlength, truncating or padding with zeros if necessary.static float[]resize(float[] array, int length) Returns an array containing the same elements as the givenarraybut specifiedlength, truncating or padding with zeros if necessary.static int[]resize(int[] array, int length) Returns an array containing the same elements as the givenarraybut specifiedlength, truncating or padding with zeros if necessary.static long[]resize(long[] array, int length) Returns an array containing the same elements as the givenarraybut specifiedlength, truncating or padding with zeros if necessary.static short[]resize(short[] array, int length) Returns an array containing the same elements as the givenarraybut specifiedlength, truncating or padding with zeros if necessary.static <E> E[]resize(E[] array, int length) Returns an array containing the same elements as the givenarraybut with the specifiedlength, truncating or padding withnullif necessary.static voidreverse(int[] values) Reverses the order of elements in the given array.static voidReverses the order of elements in the given array.static voidswap(byte[] data, int i0, int i1) Swaps the elements at the given indices in the given array ofbytevalues.static voidswap(char[] data, int i0, int i1) Swaps the elements at the given indices in the given array ofcharvalues.static voidswap(double[] data, int i0, int i1) Swaps the elements at the given indices in the given array ofdoublevalues.static voidswap(float[] data, int i0, int i1) Swaps the elements at the given indices in the given array offloatvalues.static voidswap(int[] data, int i0, int i1) Swaps the elements at the given indices in the given array ofintvalues.static voidswap(long[] data, int i0, int i1) Swaps the elements at the given indices in the given array oflongvalues.static voidswap(short[] data, int i0, int i1) Swaps the elements at the given indices in the given array ofshortvalues.static voidSwaps the elements at the given indices in the given array ofObjectvalues.static int[]unionOfSorted(int[] array1, int[] array2) Returns the union of two sorted arrays.
- 
Field Details- 
EMPTY_DOUBLEpublic static final double[] EMPTY_DOUBLEAn empty array ofdoubleprimitive type. Such arrays are immutable and can be safely shared.
- 
EMPTY_FLOATpublic static final float[] EMPTY_FLOATAn empty array offloatprimitive type. Such arrays are immutable and can be safely shared.
- 
EMPTY_LONGpublic static final long[] EMPTY_LONGAn empty array oflongprimitive type. Such arrays are immutable and can be safely shared.
- 
EMPTY_INTpublic static final int[] EMPTY_INTAn empty array ofintprimitive type. Such arrays are immutable and can be safely shared.
- 
EMPTY_SHORTpublic static final short[] EMPTY_SHORTAn empty array ofshortprimitive type. Such arrays are immutable and can be safely shared.
- 
EMPTY_BYTEpublic static final byte[] EMPTY_BYTEAn empty array ofbyteprimitive type. Such arrays are immutable and can be safely shared.
- 
EMPTY_CHARpublic static final char[] EMPTY_CHARAn empty array ofcharprimitive type. Such arrays are immutable and can be safely shared.
- 
EMPTY_BOOLEANpublic static final boolean[] EMPTY_BOOLEANAn empty array ofbooleanprimitive type. Such arrays are immutable and can be safely shared.
 
- 
- 
Method Details- 
resizeReturns an array containing the same elements as the givenarraybut with the specifiedlength, truncating or padding withnullif necessary.- If the given lengthis longer than the length of the givenarray, then the returned array will contain all the elements ofarrayat index i <array.length. Elements at index i >=array.lengthare initialized tonull.
- If the given lengthis shorter than the length of the givenarray, then the returned array will contain only the elements ofarrayat index i <length. Remaining elements are not copied.
- If the given lengthis equal to the length of the givenarray, thenarrayis returned unchanged. No copy is performed. This behavior is different than theArrays.copyOf(Object[], int)one.
 null, then this method unconditionally returnsnullno matter the value of thelengthargument.- Type Parameters:
- E- the array elements.
- Parameters:
- array- array to resize, or- null.
- length- length of the desired array.
- Returns:
- a new array of the requested length, or arrayif the given array isnullor already have the requested length.
- Throws:
- NegativeArraySizeException- if- lengthis negative.
- See Also:
 
- If the given 
- 
resizeReturns an array containing the same elements as the givenarraybut specifiedlength, truncating or padding with zeros if necessary. This method returnsnullif and only if the given array isnull, in which case the value of thelengthargument is ignored.- Parameters:
- array- array to resize, or- null.
- length- length of the desired array.
- Returns:
- a new array of the requested length, or arrayif the given array isnullor already have the requested length.
- Throws:
- NegativeArraySizeException- if- lengthis negative.
- See Also:
 
- 
resizeReturns an array containing the same elements as the givenarraybut specifiedlength, truncating or padding with zeros if necessary. This method returnsnullif and only if the given array isnull, in which case the value of thelengthargument is ignored.- Parameters:
- array- array to resize, or- null.
- length- length of the desired array.
- Returns:
- a new array of the requested length, or arrayif the given array isnullor already have the requested length.
- Throws:
- NegativeArraySizeException- if- lengthis negative.
- See Also:
 
- 
resizeReturns an array containing the same elements as the givenarraybut specifiedlength, truncating or padding with zeros if necessary. This method returnsnullif and only if the given array isnull, in which case the value of thelengthargument is ignored.- Parameters:
- array- array to resize, or- null.
- length- length of the desired array.
- Returns:
- a new array of the requested length, or arrayif the given array isnullor already have the requested length.
- Throws:
- NegativeArraySizeException- if- lengthis negative.
- See Also:
 
- 
resizeReturns an array containing the same elements as the givenarraybut specifiedlength, truncating or padding with zeros if necessary. This method returnsnullif and only if the given array isnull, in which case the value of thelengthargument is ignored.- Parameters:
- array- array to resize, or- null.
- length- length of the desired array.
- Returns:
- a new array of the requested length, or arrayif the given array isnullor already have the requested length.
- Throws:
- NegativeArraySizeException- if- lengthis negative.
- See Also:
 
- 
resizeReturns an array containing the same elements as the givenarraybut specifiedlength, truncating or padding with zeros if necessary. This method returnsnullif and only if the given array isnull, in which case the value of thelengthargument is ignored.- Parameters:
- array- array to resize, or- null.
- length- length of the desired array.
- Returns:
- a new array of the requested length, or arrayif the given array isnullor already have the requested length.
- Throws:
- NegativeArraySizeException- if- lengthis negative.
- See Also:
 
- 
resizeReturns an array containing the same elements as the givenarraybut specifiedlength, truncating or padding with zeros if necessary. This method returnsnullif and only if the given array isnull, in which case the value of thelengthargument is ignored.- Parameters:
- array- array to resize, or- null.
- length- length of the desired array.
- Returns:
- a new array of the requested length, or arrayif the given array isnullor already have the requested length.
- Throws:
- NegativeArraySizeException- if- lengthis negative.
- See Also:
 
- 
resizeReturns an array containing the same elements as the givenarraybut specifiedlength, truncating or padding with zeros if necessary. This method returnsnullif and only if the given array isnull, in which case the value of thelengthargument is ignored.- Parameters:
- array- array to resize, or- null.
- length- length of the desired array.
- Returns:
- a new array of the requested length, or arrayif the given array isnullor already have the requested length.
- Throws:
- NegativeArraySizeException- if- lengthis negative.
- See Also:
 
- 
resizeReturns an array containing the same elements as the givenarraybut specifiedlength, truncating or padding withfalseif necessary. This method returnsnullif and only if the given array isnull, in which case the value of thelengthargument is ignored.- Parameters:
- array- array to resize, or- null.
- length- length of the desired array.
- Returns:
- a new array of the requested length, or arrayif the given array isnullor already have the requested length.
- Throws:
- NegativeArraySizeException- if- lengthis negative.
- See Also:
 
- 
removepublic static <E> E[] remove(E[] array, int first, int length) throws NullArgumentException, IllegalArgumentException, IndexOutOfBoundsException Returns an array containing the same elements than the given array except for the given range. If thelengthargument is 0, then this method returns thearrayreference unchanged. Otherwise this method creates a new array. In every cases, the given array is never modified.- Type Parameters:
- E- the type of array elements.
- Parameters:
- array- array from which to remove elements. Can be- nullonly if- lengthis 0.
- first- index of the first element to remove from the given- array.
- length- number of elements to remove.
- Returns:
- array with the same elements than the given arrayexcept for the removed elements, orarray(which may be null) iflengthis 0.
- Throws:
- NullArgumentException- if- arrayis null and- lengthis different than 0.
- IllegalArgumentException- if- lengthis negative.
- IndexOutOfBoundsException- if- firstor- first+lengthis out of array bounds.
- See Also:
 
- 
removepublic static double[] remove(double[] array, int first, int length) throws NullArgumentException, IllegalArgumentException, IndexOutOfBoundsException Returns an array containing the same elements than the given array except for the given range. If thelengthargument is 0, then this method returns thearrayreference unchanged, except for empty arrays. Otherwise this method creates a new array. In every cases, the given array is never modified.- Parameters:
- array- array from which to remove elements. Can be- nullonly if- lengthis 0.
- first- index of the first element to remove from the given- array.
- length- number of elements to remove.
- Returns:
- array with the same elements than the given arrayexcept for the removed elements, orarray(which may be null) iflengthis 0.
- Throws:
- NullArgumentException- if- arrayis null and- lengthis different than 0.
- IllegalArgumentException- if- lengthis negative.
- IndexOutOfBoundsException- if- firstor- first+lengthis out of array bounds.
- See Also:
 
- 
removepublic static float[] remove(float[] array, int first, int length) throws NullArgumentException, IllegalArgumentException, IndexOutOfBoundsException Returns an array containing the same elements than the given array except for the given range. If thelengthargument is 0, then this method returns thearrayreference unchanged, except for empty arrays. Otherwise this method creates a new array. In every cases, the given array is never modified.- Parameters:
- array- array from which to remove elements. Can be- nullonly if- lengthis 0.
- first- index of the first element to remove from the given- array.
- length- number of elements to remove.
- Returns:
- array with the same elements than the given arrayexcept for the removed elements, orarray(which may be null) iflengthis 0.
- Throws:
- NullArgumentException- if- arrayis null and- lengthis different than 0.
- IllegalArgumentException- if- lengthis negative.
- IndexOutOfBoundsException- if- firstor- first+lengthis out of array bounds.
- See Also:
 
- 
removepublic static long[] remove(long[] array, int first, int length) throws NullArgumentException, IllegalArgumentException, IndexOutOfBoundsException Returns an array containing the same elements than the given array except for the given range. If thelengthargument is 0, then this method returns thearrayreference unchanged, except for empty arrays. Otherwise this method creates a new array. In every cases, the given array is never modified.- Parameters:
- array- array from which to remove elements. Can be- nullonly if- lengthis 0.
- first- index of the first element to remove from the given- array.
- length- number of elements to remove.
- Returns:
- array with the same elements than the given arrayexcept for the removed elements, orarray(which may be null) iflengthis 0.
- Throws:
- NullArgumentException- if- arrayis null and- lengthis different than 0.
- IllegalArgumentException- if- lengthis negative.
- IndexOutOfBoundsException- if- firstor- first+lengthis out of array bounds.
- See Also:
 
- 
removepublic static int[] remove(int[] array, int first, int length) throws NullArgumentException, IllegalArgumentException, IndexOutOfBoundsException Returns an array containing the same elements than the given array except for the given range. If thelengthargument is 0, then this method returns thearrayreference unchanged, except for empty arrays. Otherwise this method creates a new array. In every cases, the given array is never modified.- Parameters:
- array- array from which to remove elements. Can be- nullonly if- lengthis 0.
- first- index of the first element to remove from the given- array.
- length- number of elements to remove.
- Returns:
- array with the same elements than the given arrayexcept for the removed elements, orarray(which may be null) iflengthis 0.
- Throws:
- NullArgumentException- if- arrayis null and- lengthis different than 0.
- IllegalArgumentException- if- lengthis negative.
- IndexOutOfBoundsException- if- firstor- first+lengthis out of array bounds.
- See Also:
 
- 
removepublic static short[] remove(short[] array, int first, int length) throws NullArgumentException, IllegalArgumentException, IndexOutOfBoundsException Returns an array containing the same elements than the given array except for the given range. If thelengthargument is 0, then this method returns thearrayreference unchanged, except for empty arrays. Otherwise this method creates a new array. In every cases, the given array is never modified.- Parameters:
- array- array from which to remove elements. Can be- nullonly if- lengthis 0.
- first- index of the first element to remove from the given- array.
- length- number of elements to remove.
- Returns:
- array with the same elements than the given arrayexcept for the removed elements, orarray(which may be null) iflengthis 0.
- Throws:
- NullArgumentException- if- arrayis null and- lengthis different than 0.
- IllegalArgumentException- if- lengthis negative.
- IndexOutOfBoundsException- if- firstor- first+lengthis out of array bounds.
- See Also:
 
- 
removepublic static byte[] remove(byte[] array, int first, int length) throws NullArgumentException, IllegalArgumentException, IndexOutOfBoundsException Returns an array containing the same elements than the given array except for the given range. If thelengthargument is 0, then this method returns thearrayreference unchanged, except for empty arrays. Otherwise this method creates a new array. In every cases, the given array is never modified.- Parameters:
- array- array from which to remove elements. Can be- nullonly if- lengthis 0.
- first- index of the first element to remove from the given- array.
- length- number of elements to remove.
- Returns:
- array with the same elements than the given arrayexcept for the removed elements, orarray(which may be null) iflengthis 0.
- Throws:
- NullArgumentException- if- arrayis null and- lengthis different than 0.
- IllegalArgumentException- if- lengthis negative.
- IndexOutOfBoundsException- if- firstor- first+lengthis out of array bounds.
- See Also:
 
- 
removepublic static char[] remove(char[] array, int first, int length) throws NullArgumentException, IllegalArgumentException, IndexOutOfBoundsException Returns an array containing the same elements than the given array except for the given range. If thelengthargument is 0, then this method returns thearrayreference unchanged, except for empty arrays. Otherwise this method creates a new array. In every cases, the given array is never modified.- Parameters:
- array- array from which to remove elements. Can be- nullonly if- lengthis 0.
- first- index of the first element to remove from the given- array.
- length- number of elements to remove.
- Returns:
- array with the same elements than the given arrayexcept for the removed elements, orarray(which may be null) iflengthis 0.
- Throws:
- NullArgumentException- if- arrayis null and- lengthis different than 0.
- IllegalArgumentException- if- lengthis negative.
- IndexOutOfBoundsException- if- firstor- first+lengthis out of array bounds.
- See Also:
 
- 
removepublic static boolean[] remove(boolean[] array, int first, int length) throws NullArgumentException, IllegalArgumentException, IndexOutOfBoundsException Returns an array containing the same elements than the given array except for the given range. If thelengthargument is 0, then this method returns thearrayreference unchanged, except for empty arrays. Otherwise this method creates a new array. In every cases, the given array is never modified.- Parameters:
- array- array from which to remove elements. Can be- nullonly if- lengthis 0.
- first- index of the first element to remove from the given- array.
- length- number of elements to remove.
- Returns:
- array with the same elements than the given arrayexcept for the removed elements, orarray(which may be null) iflengthis 0.
- Throws:
- NullArgumentException- if- arrayis null and- lengthis different than 0.
- IllegalArgumentException- if- lengthis negative.
- IndexOutOfBoundsException- if- firstor- first+lengthis out of array bounds.
- See Also:
 
- 
insertpublic static <E> E[] insert(E[] array, int first, int length) throws NullArgumentException, IllegalArgumentException, IndexOutOfBoundsException Returns an array containing the same elements than the given array, with additional "spaces" in the given range. These "spaces" will be made up ofnullelements. If thelengthargument is 0, then this method returns thearrayreference unchanged. Otherwise this method creates a new array. In every cases, the given array is never modified.- Type Parameters:
- E- the type of array elements.
- Parameters:
- array- array in which to insert spaces. Can be- nullonly if- lengthis 0.
- first- index where the first space will be inserted. All- arrayelements having an index equal to or higher than- indexwill be moved forward. Can be- array.lengthfor inserting spaces at the end of the array.
- length- number of spaces to insert.
- Returns:
- array containing the arrayelements with the additional space inserted, orarray(which may be null) iflengthis 0.
- Throws:
- NullArgumentException- if- arrayis null and- lengthis different than 0.
- IllegalArgumentException- if- lengthis negative.
- IndexOutOfBoundsException- if- firstor- first+lengthis out of array bounds.
- See Also:
 
- 
insertpublic static double[] insert(double[] array, int first, int length) throws NullArgumentException, IllegalArgumentException, IndexOutOfBoundsException Returns an array containing the same elements than the given array, with additional "spaces" in the given range. These "spaces" will be made up of elements initialized to zero. If thelengthargument is 0, then this method returns thearrayreference unchanged. Otherwise this method creates a new array. In every cases, the given array is never modified.- Parameters:
- array- array in which to insert spaces. Can be- nullonly if- lengthis 0.
- first- index where the first space will be inserted. All- arrayelements having an index equal to or higher than- indexwill be moved forward. Can be- array.lengthfor inserting spaces at the end of the array.
- length- number of spaces to insert.
- Returns:
- array containing the arrayelements with the additional space inserted, orarray(which may be null) iflengthis 0.
- Throws:
- NullArgumentException- if- arrayis null and- lengthis different than 0.
- IllegalArgumentException- if- lengthis negative.
- IndexOutOfBoundsException- if- firstor- first+lengthis out of array bounds.
- See Also:
 
- 
insertpublic static float[] insert(float[] array, int first, int length) throws NullArgumentException, IllegalArgumentException, IndexOutOfBoundsException Returns an array containing the same elements than the given array, with additional "spaces" in the given range. These "spaces" will be made up of elements initialized to zero. If thelengthargument is 0, then this method returns thearrayreference unchanged. Otherwise this method creates a new array. In every cases, the given array is never modified.- Parameters:
- array- array in which to insert spaces. Can be- nullonly if- lengthis 0.
- first- index where the first space will be inserted. All- arrayelements having an index equal to or higher than- indexwill be moved forward. Can be- array.lengthfor inserting spaces at the end of the array.
- length- number of spaces to insert.
- Returns:
- array containing the arrayelements with the additional space inserted, orarray(which may be null) iflengthis 0.
- Throws:
- NullArgumentException- if- arrayis null and- lengthis different than 0.
- IllegalArgumentException- if- lengthis negative.
- IndexOutOfBoundsException- if- firstor- first+lengthis out of array bounds.
- See Also:
 
- 
insertpublic static long[] insert(long[] array, int first, int length) throws NullArgumentException, IllegalArgumentException, IndexOutOfBoundsException Returns an array containing the same elements than the given array, with additional "spaces" in the given range. These "spaces" will be made up of elements initialized to zero. If thelengthargument is 0, then this method returns thearrayreference unchanged. Otherwise this method creates a new array. In every cases, the given array is never modified.- Parameters:
- array- array in which to insert spaces. Can be- nullonly if- lengthis 0.
- first- index where the first space will be inserted. All- arrayelements having an index equal to or higher than- indexwill be moved forward. Can be- array.lengthfor inserting spaces at the end of the array.
- length- number of spaces to insert.
- Returns:
- array containing the arrayelements with the additional space inserted, orarray(which may be null) iflengthis 0.
- Throws:
- NullArgumentException- if- arrayis null and- lengthis different than 0.
- IllegalArgumentException- if- lengthis negative.
- IndexOutOfBoundsException- if- firstor- first+lengthis out of array bounds.
- See Also:
 
- 
insertpublic static int[] insert(int[] array, int first, int length) throws NullArgumentException, IllegalArgumentException, IndexOutOfBoundsException Returns an array containing the same elements than the given array, with additional "spaces" in the given range. These "spaces" will be made up of elements initialized to zero. If thelengthargument is 0, then this method returns thearrayreference unchanged. Otherwise this method creates a new array. In every cases, the given array is never modified.- Parameters:
- array- array in which to insert spaces. Can be- nullonly if- lengthis 0.
- first- index where the first space will be inserted. All- arrayelements having an index equal to or higher than- indexwill be moved forward. Can be- array.lengthfor inserting spaces at the end of the array.
- length- number of spaces to insert.
- Returns:
- array containing the arrayelements with the additional space inserted, orarray(which may be null) iflengthis 0.
- Throws:
- NullArgumentException- if- arrayis null and- lengthis different than 0.
- IllegalArgumentException- if- lengthis negative.
- IndexOutOfBoundsException- if- firstor- first+lengthis out of array bounds.
- See Also:
 
- 
insertpublic static short[] insert(short[] array, int first, int length) throws NullArgumentException, IllegalArgumentException, IndexOutOfBoundsException Returns an array containing the same elements than the given array, with additional "spaces" in the given range. These "spaces" will be made up of elements initialized to zero. If thelengthargument is 0, then this method returns thearrayreference unchanged. Otherwise this method creates a new array. In every cases, the given array is never modified.- Parameters:
- array- array in which to insert spaces. Can be- nullonly if- lengthis 0.
- first- index where the first space should be inserted. All- arrayelements having an index equal to or higher than- indexwill be moved forward.
- length- number of spaces to insert.
- Returns:
- array containing the arrayelements with the additional space inserted, orarray(which may be null) iflengthis 0.
- Throws:
- NullArgumentException- if- arrayis null and- lengthis different than 0.
- IllegalArgumentException- if- lengthis negative.
- IndexOutOfBoundsException- if- firstor- first+lengthis out of array bounds.
- See Also:
 
- 
insertpublic static byte[] insert(byte[] array, int first, int length) throws NullArgumentException, IllegalArgumentException, IndexOutOfBoundsException Returns an array containing the same elements than the given array, with additional "spaces" in the given range. These "spaces" will be made up of elements initialized to zero. If thelengthargument is 0, then this method returns thearrayreference unchanged. Otherwise this method creates a new array. In every cases, the given array is never modified.- Parameters:
- array- array in which to insert spaces. Can be- nullonly if- lengthis 0.
- first- index where the first space will be inserted. All- arrayelements having an index equal to or higher than- indexwill be moved forward. Can be- array.lengthfor inserting spaces at the end of the array.
- length- number of spaces to insert.
- Returns:
- array containing the arrayelements with the additional space inserted, orarray(which may be null) iflengthis 0.
- Throws:
- NullArgumentException- if- arrayis null and- lengthis different than 0.
- IllegalArgumentException- if- lengthis negative.
- IndexOutOfBoundsException- if- firstor- first+lengthis out of array bounds.
- See Also:
 
- 
insertpublic static char[] insert(char[] array, int first, int length) throws NullArgumentException, IllegalArgumentException, IndexOutOfBoundsException Returns an array containing the same elements than the given array, with additional "spaces" in the given range. These "spaces" will be made up of elements initialized to zero. If thelengthargument is 0, then this method returns thearrayreference unchanged. Otherwise this method creates a new array. In every cases, the given array is never modified.- Parameters:
- array- array in which to insert spaces. Can be- nullonly if- lengthis 0.
- first- index where the first space will be inserted. All- arrayelements having an index equal to or higher than- indexwill be moved forward. Can be- array.lengthfor inserting spaces at the end of the array.
- length- number of spaces to insert.
- Returns:
- array containing the arrayelements with the additional space inserted, orarray(which may be null) iflengthis 0.
- Throws:
- NullArgumentException- if- arrayis null and- lengthis different than 0.
- IllegalArgumentException- if- lengthis negative.
- IndexOutOfBoundsException- if- firstor- first+lengthis out of array bounds.
- See Also:
 
- 
insertpublic static boolean[] insert(boolean[] array, int first, int length) throws NullArgumentException, IllegalArgumentException, IndexOutOfBoundsException Returns an array containing the same elements than the given array, with additional "spaces" in the given range. These "spaces" will be made up of elements initialized tofalse. If thelengthargument is 0, then this method returns thearrayreference unchanged. Otherwise this method creates a new array. In every cases, the given array is never modified.- Parameters:
- array- array in which to insert spaces. Can be- nullonly if- lengthis 0.
- first- index where the first space will be inserted. All- arrayelements having an index equal to or higher than- indexwill be moved forward. Can be- array.lengthfor inserting spaces at the end of the array.
- length- number of spaces to insert.
- Returns:
- array containing the arrayelements with the additional space inserted, orarray(which may be null) iflengthis 0.
- Throws:
- NullArgumentException- if- arrayis null and- lengthis different than 0.
- IllegalArgumentException- if- lengthis negative.
- IndexOutOfBoundsException- if- firstor- first+lengthis out of array bounds.
- See Also:
 
- 
insertpublic static <E> E[] insert(E[] src, int srcOff, E[] dst, int dstOff, int length) throws NullArgumentException, IllegalArgumentException, IndexOutOfBoundsException Returns an array containing the same elements than the given array, with the content of another array inserted at the given index. If thelengthargument is 0, then this method returns thedstreference unchanged. Otherwise this method creates a new array. In every cases, the given arrays are never modified.- Type Parameters:
- E- the type of array elements.
- Parameters:
- src- array to entirely or partially insert into- dst. Can be null only if- lengthis 0.
- srcOff- index of the first element of- srcto insert into- dst.
- dst- array in which to insert- srcdata. Can be null only if- lengthis 0.
- dstOff- index of the first element in- dstwhere to insert- srcdata. All elements of- dstwhose index is equal to or greater than- dstOffwill be moved forward.
- length- number of- srcelements to insert.
- Returns:
- array which contains the merge of srcanddst. This method returns directlydstwhenlengthis zero, but never returnsrc.
- Throws:
- NullArgumentException- if- srcor- dstis null while- lengthis different than 0.
- IllegalArgumentException- if- lengthis negative.
- IndexOutOfBoundsException- if- srcOff,- srcOff+lengthor- dstOffis out of array bounds.
 
- 
insertpublic static double[] insert(double[] src, int srcOff, double[] dst, int dstOff, int length) throws NullArgumentException, IllegalArgumentException, IndexOutOfBoundsException Returns an array containing the same elements than the given array, with the content of another array inserted at the given index. If thelengthargument is 0, then this method returns thedstreference unchanged. Otherwise this method creates a new array. In every cases, the given arrays are never modified.- Parameters:
- src- array to entirely or partially insert into- dst. Can be null only if- lengthis 0.
- srcOff- index of the first element of- srcto insert into- dst.
- dst- array in which to insert- srcdata. Can be null only if- lengthis 0.
- dstOff- index of the first element in- dstwhere to insert- srcdata. All elements of- dstwhose index is equal to or greater than- dstOffwill be moved forward.
- length- number of- srcelements to insert.
- Returns:
- array which contains the merge of srcanddst. This method returns directlydstwhenlengthis zero, but never returnsrc.
- Throws:
- NullArgumentException- if- srcor- dstis null while- lengthis different than 0.
- IllegalArgumentException- if- lengthis negative.
- IndexOutOfBoundsException- if- srcOff,- srcOff+lengthor- dstOffis out of array bounds.
 
- 
insertpublic static float[] insert(float[] src, int srcOff, float[] dst, int dstOff, int length) throws NullArgumentException, IllegalArgumentException, IndexOutOfBoundsException Returns an array containing the same elements than the given array, with the content of another array inserted at the given index. If thelengthargument is 0, then this method returns thedstreference unchanged. Otherwise this method creates a new array. In every cases, the given arrays are never modified.- Parameters:
- src- array to entirely or partially insert into- dst. Can be null only if- lengthis 0.
- srcOff- index of the first element of- srcto insert into- dst.
- dst- array in which to insert- srcdata. Can be null only if- lengthis 0.
- dstOff- index of the first element in- dstwhere to insert- srcdata. All elements of- dstwhose index is equal to or greater than- dstOffwill be moved forward.
- length- number of- srcelements to insert.
- Returns:
- array which contains the merge of srcanddst. This method returns directlydstwhenlengthis zero, but never returnsrc.
- Throws:
- NullArgumentException- if- srcor- dstis null while- lengthis different than 0.
- IllegalArgumentException- if- lengthis negative.
- IndexOutOfBoundsException- if- srcOff,- srcOff+lengthor- dstOffis out of array bounds.
 
- 
insertpublic static long[] insert(long[] src, int srcOff, long[] dst, int dstOff, int length) throws NullArgumentException, IllegalArgumentException, IndexOutOfBoundsException Returns an array containing the same elements than the given array, with the content of another array inserted at the given index. If thelengthargument is 0, then this method returns thedstreference unchanged. Otherwise this method creates a new array. In every cases, the given arrays are never modified.- Parameters:
- src- array to entirely or partially insert into- dst. Can be null only if- lengthis 0.
- srcOff- index of the first element of- srcto insert into- dst.
- dst- array in which to insert- srcdata. Can be null only if- lengthis 0.
- dstOff- index of the first element in- dstwhere to insert- srcdata. All elements of- dstwhose index is equal to or greater than- dstOffwill be moved forward.
- length- number of- srcelements to insert.
- Returns:
- array which contains the merge of srcanddst. This method returns directlydstwhenlengthis zero, but never returnsrc.
- Throws:
- NullArgumentException- if- srcor- dstis null while- lengthis different than 0.
- IllegalArgumentException- if- lengthis negative.
- IndexOutOfBoundsException- if- srcOff,- srcOff+lengthor- dstOffis out of array bounds.
 
- 
insertpublic static int[] insert(int[] src, int srcOff, int[] dst, int dstOff, int length) throws NullArgumentException, IllegalArgumentException, IndexOutOfBoundsException Returns an array containing the same elements than the given array, with the content of another array inserted at the given index. If thelengthargument is 0, then this method returns thedstreference unchanged. Otherwise this method creates a new array. In every cases, the given arrays are never modified.- Parameters:
- src- array to entirely or partially insert into- dst. Can be null only if- lengthis 0.
- srcOff- index of the first element of- srcto insert into- dst.
- dst- array in which to insert- srcdata. Can be null only if- lengthis 0.
- dstOff- index of the first element in- dstwhere to insert- srcdata. All elements of- dstwhose index is equal to or greater than- dstOffwill be moved forward.
- length- number of- srcelements to insert.
- Returns:
- array which contains the merge of srcanddst. This method returns directlydstwhenlengthis zero, but never returnsrc.
- Throws:
- NullArgumentException- if- srcor- dstis null while- lengthis different than 0.
- IllegalArgumentException- if- lengthis negative.
- IndexOutOfBoundsException- if- srcOff,- srcOff+lengthor- dstOffis out of array bounds.
 
- 
insertpublic static short[] insert(short[] src, int srcOff, short[] dst, int dstOff, int length) throws NullArgumentException, IllegalArgumentException, IndexOutOfBoundsException Returns an array containing the same elements than the given array, with the content of another array inserted at the given index. If thelengthargument is 0, then this method returns thedstreference unchanged. Otherwise this method creates a new array. In every cases, the given arrays are never modified.- Parameters:
- src- array to entirely or partially insert into- dst. Can be null only if- lengthis 0.
- srcOff- index of the first element of- srcto insert into- dst.
- dst- array in which to insert- srcdata. Can be null only if- lengthis 0.
- dstOff- index of the first element in- dstwhere to insert- srcdata. All elements of- dstwhose index is equal to or greater than- dstOffwill be moved forward.
- length- number of- srcelements to insert.
- Returns:
- array which contains the merge of srcanddst. This method returns directlydstwhenlengthis zero, but never returnsrc.
- Throws:
- NullArgumentException- if- srcor- dstis null while- lengthis different than 0.
- IllegalArgumentException- if- lengthis negative.
- IndexOutOfBoundsException- if- srcOff,- srcOff+lengthor- dstOffis out of array bounds.
 
- 
insertpublic static byte[] insert(byte[] src, int srcOff, byte[] dst, int dstOff, int length) throws NullArgumentException, IllegalArgumentException, IndexOutOfBoundsException Returns an array containing the same elements than the given array, with the content of another array inserted at the given index. If thelengthargument is 0, then this method returns thedstreference unchanged. Otherwise this method creates a new array. In every cases, the given arrays are never modified.- Parameters:
- src- array to entirely or partially insert into- dst. Can be null only if- lengthis 0.
- srcOff- index of the first element of- srcto insert into- dst.
- dst- array in which to insert- srcdata. Can be null only if- lengthis 0.
- dstOff- index of the first element in- dstwhere to insert- srcdata. All elements of- dstwhose index is equal to or greater than- dstOffwill be moved forward.
- length- number of- srcelements to insert.
- Returns:
- array which contains the merge of srcanddst. This method returns directlydstwhenlengthis zero, but never returnsrc.
- Throws:
- NullArgumentException- if- srcor- dstis null while- lengthis different than 0.
- IllegalArgumentException- if- lengthis negative.
- IndexOutOfBoundsException- if- srcOff,- srcOff+lengthor- dstOffis out of array bounds.
 
- 
insertpublic static char[] insert(char[] src, int srcOff, char[] dst, int dstOff, int length) throws NullArgumentException, IllegalArgumentException, IndexOutOfBoundsException Returns an array containing the same elements than the given array, with the content of another array inserted at the given index. If thelengthargument is 0, then this method returns thedstreference unchanged. Otherwise this method creates a new array. In every cases, the given arrays are never modified.- Parameters:
- src- array to entirely or partially insert into- dst. Can be null only if- lengthis 0.
- srcOff- index of the first element of- srcto insert into- dst.
- dst- array in which to insert- srcdata. Can be null only if- lengthis 0.
- dstOff- index of the first element in- dstwhere to insert- srcdata. All elements of- dstwhose index is equal to or greater than- dstOffwill be moved forward.
- length- number of- srcelements to insert.
- Returns:
- array which contains the merge of srcanddst. This method returns directlydstwhenlengthis zero, but never returnsrc.
- Throws:
- NullArgumentException- if- srcor- dstis null while- lengthis different than 0.
- IllegalArgumentException- if- lengthis negative.
- IndexOutOfBoundsException- if- srcOff,- srcOff+lengthor- dstOffis out of array bounds.
 
- 
insertpublic static boolean[] insert(boolean[] src, int srcOff, boolean[] dst, int dstOff, int length) throws NullArgumentException, IllegalArgumentException, IndexOutOfBoundsException Returns an array containing the same elements than the given array, with the content of another array inserted at the given index. If thelengthargument is 0, then this method returns thedstreference unchanged. Otherwise this method creates a new array. In every cases, the given arrays are never modified.- Parameters:
- src- array to entirely or partially insert into- dst. Can be null only if- lengthis 0.
- srcOff- index of the first element of- srcto insert into- dst.
- dst- array in which to insert- srcdata. Can be null only if- lengthis 0.
- dstOff- index of the first element in- dstwhere to insert- srcdata. All elements of- dstwhose index is equal to or greater than- dstOffwill be moved forward.
- length- number of- srcelements to insert.
- Returns:
- array which contains the merge of srcanddst. This method returns directlydstwhenlengthis zero, but never returnsrc.
- Throws:
- NullArgumentException- if- srcor- dstis null while- lengthis different than 0.
- IllegalArgumentException- if- lengthis negative.
- IndexOutOfBoundsException- if- srcOff,- srcOff+lengthor- dstOffis out of array bounds.
 
- 
appendReturns a copy of the given array with a single element appended at the end. This method should be invoked only on rare occasions. If many elements are to be added, useArrayListinstead.- Type Parameters:
- T- the type of elements in the array.
- Parameters:
- array- the array to copy with a new element. The original array will not be modified.
- element- the element to add (can be null).
- Returns:
- a copy of the given array with the given element appended at the end.
- Throws:
- NullArgumentException- if the given array is null.
- See Also:
 
- 
removeDuplicatedRemoves the duplicated elements in the given array. This method should be invoked only for small arrays, typically less than 10 distinct elements. For larger arrays, useLinkedHashSetinstead.This method compares all pair of elements using the Objects.equals(Object, Object)method - so null elements are allowed. If duplicated values are found, then only the first occurrence is retained; the second occurrence is removed in-place. After all elements have been compared, this method returns the number of remaining elements in the array. The free space at the end of the array is padded withnullvalues.Callers can obtain an array of appropriate length using the following idiom. Note that this idiom will create a new array only if necessary: T[] array = ...; array = resize(array, removeDuplicated(array)); API note: This method return type is not an array in order to make obvious that the given array will be modified in-place. This behavior is different than the behavior of many other methods in this class, which do not modify the given source array.- Parameters:
- array- array from which to remove duplicated elements, or- null.
- Returns:
- the number of remaining elements in the given array, or 0 if the given arraywas null.
 
- 
reverseReverses the order of elements in the given array. This operation is performed in-place. If the given array isnull, then this method does nothing.- Parameters:
- entries- the array in which to reverse the order of elements, or- nullif none.
 
- 
reversepublic static void reverse(int[] values) Reverses the order of elements in the given array. This operation is performed in-place. If the given array isnull, then this method does nothing.- Parameters:
- values- the array in which to reverse the order of elements, or- nullif none.
 
- 
rangepublic static int[] range(int start, int end) Returns the ordered values in the range fromstartinclusive toendexclusive. This method performs the same work thanIntStream.range(int, int)but returning values in an array instead of in a stream. This method is okay for small sequences; for large sequences the stream approach should be preferred.Purpose: this method is convenient for enumerating dimensions in a coordinate reference system or bands in an image. Some methods in the Java library or in Apache SIS want dimensions or bands to be specified by their indices. An example from the Java library is theFor any array returned by this method,bankIndicesargument inRaster.createBandedRaster(…, bankIndices, …). An example from Apache SIS is therangeargument inGridCoverageResource.read(…, range). Thisrange(start, end)method can be used in the common case where all bands are wanted in order.isRange(start, array)true.- Parameters:
- start- first value (inclusive) in the array to return.
- end- upper bound (exclusive) of values in the array to return.
- Returns:
- a finite arithmetic progression of common difference of 1 with all values in the specified range.
- Throws:
- ArithmeticException- if the sequence length is greater than- Integer.MAX_VALUE.
- Since:
- 1.0
- See Also:
 
- 
isRangepublic static boolean isRange(int start, int[] array) Returnstrueif the given array is a finite arithmetic progression starting at the given value and having a common difference of 1. More specifically:- If arrayisnull, then returnfalse.
- Otherwise if arrayis empty, then returntruefor consistency withrange(int, int).
- Otherwise for any index 0 ≤ i < array.length, ifarray[i]is equal tostart + i(computed as if no overflow occurs), then returntrue.
- Otherwise return false.
 Example:This method is useful whenisRange(1, array)returnstrueif the given array is{1, 2, 3, 4}butfalseif the array is{1, 2, 4}(missing 3).arrayis an argument specified to another method, and determining that the argument values arestart,start+1,start+2, etc. allows some optimizations.- Parameters:
- start- first value expected in the given- array.
- array- the array to test, or- null.
- Returns:
- trueif the given array is non-null and equal to- range(start, start + array.length).
- Since:
- 1.0
- See Also:
 
- If 
- 
isSortedReturnstrueif all elements in the specified array are in increasing order. Special cases:- Empty arrays are considered as sorted.
- Null arrays are considered as unknown content and cause a NullPointerExceptionto be thrown.
- nullelements are considered unordered and may appear anywhere in the array; they will be silently ignored.
 - Type Parameters:
- E- the type of array elements.
- Parameters:
- array- the array to test for order.
- comparator- the comparator to use for comparing order.
- strict-- trueif elements should be strictly sorted (i.e. equal elements are not allowed), or- falseotherwise.
- Returns:
- trueif all elements in the given array are sorted in increasing order.
 
- 
isSortedReturnstrueif all elements in the specified array are in increasing order. Special cases:- Empty arrays are considered as sorted.
- Null arrays are considered as unknown content and cause a NullPointerExceptionto be thrown.
- nullelements are considered unordered and may appear anywhere in the array; they will be silently ignored.
 - Type Parameters:
- E- the type of array elements.
- Parameters:
- array- the array to test for order.
- strict-- trueif elements should be strictly sorted (i.e. equal elements are not allowed), or- falseotherwise.
- Returns:
- trueif all elements in the given array are sorted in increasing order.
 
- 
isSortedpublic static boolean isSorted(double[] array, boolean strict) Returnstrueif all elements in the specified array are in increasing order. Special cases:- Empty arrays are considered as sorted.
- Null arrays are considered as unknown content and cause a NullPointerExceptionto be thrown.
- NaNelements are considered unordered and may appear anywhere in the array; they will be silently ignored.
 - Parameters:
- array- the array to test for order.
- strict-- trueif elements should be strictly sorted (i.e. equal elements are not allowed), or- falseotherwise.
- Returns:
- trueif all elements in the given array are sorted in increasing order.
 
- 
isSortedpublic static boolean isSorted(float[] array, boolean strict) Returnstrueif all elements in the specified array are in increasing order. Special cases:- Empty arrays are considered as sorted.
- Null arrays are considered as unknown content and cause a NullPointerExceptionto be thrown.
- NaNelements are considered unordered and may appear anywhere in the array; they will be silently ignored.
 - Parameters:
- array- the array to test for order.
- strict-- trueif elements should be strictly sorted (i.e. equal elements are not allowed), or- falseotherwise.
- Returns:
- trueif all elements in the given array are sorted in increasing order.
 
- 
isSortedpublic static boolean isSorted(long[] array, boolean strict) Returnstrueif all elements in the specified array are in increasing order. Special cases:- Empty arrays are considered as sorted.
- Null arrays are considered as unknown content and cause a NullPointerExceptionto be thrown.
 - Parameters:
- array- the array to test for order.
- strict-- trueif elements should be strictly sorted (i.e. equal elements are not allowed), or- falseotherwise.
- Returns:
- trueif all elements in the given array are sorted in increasing order.
 
- 
isSortedpublic static boolean isSorted(int[] array, boolean strict) Returnstrueif all elements in the specified array are in increasing order. Special cases:- Empty arrays are considered as sorted.
- Null arrays are considered as unknown content and cause a NullPointerExceptionto be thrown.
 - Parameters:
- array- the array to test for order.
- strict-- trueif elements should be strictly sorted (i.e. equal elements are not allowed), or- falseotherwise.
- Returns:
- trueif all elements in the given array are sorted in increasing order.
 
- 
isSortedpublic static boolean isSorted(short[] array, boolean strict) Returnstrueif all elements in the specified array are in increasing order. Special cases:- Empty arrays are considered as sorted.
- Null arrays are considered as unknown content and cause a NullPointerExceptionto be thrown.
 - Parameters:
- array- the array to test for order.
- strict-- trueif elements should be strictly sorted (i.e. equal elements are not allowed), or- falseotherwise.
- Returns:
- trueif all elements in the given array are sorted in increasing order.
 
- 
isSortedpublic static boolean isSorted(byte[] array, boolean strict) Returnstrueif all elements in the specified array are in increasing order. Special cases:- Empty arrays are considered as sorted.
- Null arrays are considered as unknown content and cause a NullPointerExceptionto be thrown.
 - Parameters:
- array- the array to test for order.
- strict-- trueif elements should be strictly sorted (i.e. equal elements are not allowed), or- falseotherwise.
- Returns:
- trueif all elements in the given array are sorted in increasing order.
 
- 
isSortedpublic static boolean isSorted(char[] array, boolean strict) Returnstrueif all elements in the specified array are in increasing order. Special cases:- Empty arrays are considered as sorted.
- Null arrays are considered as unknown content and cause a NullPointerExceptionto be thrown.
 - Parameters:
- array- the array to test for order.
- strict-- trueif elements should be strictly sorted (i.e. equal elements are not allowed), or- falseotherwise.
- Returns:
- trueif all elements in the given array are sorted in increasing order.
 
- 
swapSwaps the elements at the given indices in the given array ofObjectvalues.Note: While trivial, this method is provided because its need occurs relatively often and the availability of aswapmethod makes the code easier to read.- Parameters:
- data- the array in which to swap elements.
- i0- index of one element to be swapped.
- i1- index of the other element to be swapped.
- Since:
- 0.4
 
- 
swappublic static void swap(double[] data, int i0, int i1) Swaps the elements at the given indices in the given array ofdoublevalues.Note: While trivial, this method is provided because its need occurs relatively often and the availability of aswapmethod makes the code easier to read.- Parameters:
- data- the array in which to swap elements.
- i0- index of one element to be swapped.
- i1- index of the other element to be swapped.
- Since:
- 0.4
 
- 
swappublic static void swap(float[] data, int i0, int i1) Swaps the elements at the given indices in the given array offloatvalues.- Parameters:
- data- the array in which to swap elements.
- i0- index of one element to be swapped.
- i1- index of the other element to be swapped.
- Since:
- 0.4
 
- 
swappublic static void swap(long[] data, int i0, int i1) Swaps the elements at the given indices in the given array oflongvalues.- Parameters:
- data- the array in which to swap elements.
- i0- index of one element to be swapped.
- i1- index of the other element to be swapped.
- Since:
- 0.4
 
- 
swappublic static void swap(int[] data, int i0, int i1) Swaps the elements at the given indices in the given array ofintvalues.Note: While trivial, this method is provided because its need occurs relatively often and the availability of aswapmethod makes the code easier to read.- Parameters:
- data- the array in which to swap elements.
- i0- index of one element to be swapped.
- i1- index of the other element to be swapped.
- Since:
- 0.4
 
- 
swappublic static void swap(short[] data, int i0, int i1) Swaps the elements at the given indices in the given array ofshortvalues.- Parameters:
- data- the array in which to swap elements.
- i0- index of one element to be swapped.
- i1- index of the other element to be swapped.
- Since:
- 0.4
 
- 
swappublic static void swap(byte[] data, int i0, int i1) Swaps the elements at the given indices in the given array ofbytevalues.- Parameters:
- data- the array in which to swap elements.
- i0- index of one element to be swapped.
- i1- index of the other element to be swapped.
- Since:
- 0.4
 
- 
swappublic static void swap(char[] data, int i0, int i1) Swaps the elements at the given indices in the given array ofcharvalues.- Parameters:
- data- the array in which to swap elements.
- i0- index of one element to be swapped.
- i1- index of the other element to be swapped.
- Since:
- 0.4
 
- 
replacepublic static void replace(double[] array, double search, double replacement) Replaces all occurrences of the given value by the given replacement. This method compares the values usingDouble.doubleToRawLongBits(double):- Positive zero is considered different then negative zero.
- The various possible NaN values are considered different.
 Double.NaNin the sample values of a grid coverage. This method does nothing if the given array isnullor ifsearchis the same bits pattern thanreplacement.- Parameters:
- array- the array where to perform the search and replace, or- null.
- search- the value to search.
- replacement- the replacement.
- Since:
- 1.0
 
- 
replacepublic static void replace(float[] array, float search, float replacement) Replaces all occurrences of the given value by the given replacement. This method compares the values usingFloat.floatToRawIntBits(float):- Positive zero is considered different then negative zero.
- The various possible NaN values are considered different.
 Float.NaNin the sample values of a grid coverage. This method does nothing if the given array isnullor ifsearchis the same bits pattern thanreplacement.- Parameters:
- array- the array where to perform the search and replace, or- null.
- search- the value to search.
- replacement- the replacement.
- Since:
- 1.0
 
- 
copyAsLongspublic static long[] copyAsLongs(int[] data) Returns a copy of the given array where each value has been casted to thelongtype.- Parameters:
- data- the array to copy, or- null.
- Returns:
- a copy of the given array with values casted to the longtype, ornullif the given array was null.
- Since:
- 1.1
 
- 
copyAsFloatspublic static float[] copyAsFloats(double[] data) Returns a copy of the given array where each value has been casted to thefloattype. This method does not verify if the casts would cause data loss.- Parameters:
- data- the array to copy, or- null.
- Returns:
- a copy of the given array with values casted to the floattype, ornullif the given array was null.
- Since:
- 1.0
 
- 
copyAsFloatsIfLosslesspublic static float[] copyAsFloatsIfLossless(double[] data) Returns a copy of the given array where each value has been casted to thefloattype, but only if all casts are lossless. If any cast causes data loss, then this method returnsnull. This method is equivalent to the following code, but potentially more efficient:if (isSinglePrecision(data)) { return copyAsFloat(data); } else { return null; }- Parameters:
- data- the array to copy, or- null.
- Returns:
- a copy of the given array with values casted to the floattype, ornullif the given array was null or if a cast would cause data lost.
- Since:
- 1.0
 
- 
isSinglePrecisionpublic static boolean isSinglePrecision(double... values) Returnstrueif every values in the givendoublearray could be casted to thefloattype without data lost. If this method returnstrue, then the array can be converted to thefloat[]type withcopyAsFloats(double[])and the exact samedoublevalues can still be obtained by casting back eachfloatvalue todouble.- Parameters:
- values- the values to test for their precision, or- null.
- Returns:
- trueif every values can be casted to the- floattype without data lost.
- Since:
- 1.0
 
- 
hasNaNpublic static boolean hasNaN(double[] array) Returnstrueif the specified array contains at least oneNaNvalue.- Parameters:
- array- the array to check, or- null.
- Returns:
- trueif the given array is non-null and contains at least one NaN value.
 
- 
hasNaNpublic static boolean hasNaN(float[] array) Returnstrueif the specified array contains at least oneNaNvalue.- Parameters:
- array- the array to check, or- null.
- Returns:
- trueif the given array is non-null and contains at least one NaN value.
 
- 
allEqualsReturnstrueif all values in the specified array are equal to the specified value, which may benull. If the given array is empty, then this method returnstrue.- Parameters:
- array- the array to check.
- value- the expected value.
- Returns:
- trueif all elements in the given array are equal to the given value.
- Since:
- 0.8
 
- 
allEqualspublic static boolean allEquals(double[] array, double value) Returnstrueif all values in the specified array are equal to the specified value, which may beDouble.NaN. A NaN value is considered equal to all other NaN values.- Parameters:
- array- the array to check.
- value- the expected value.
- Returns:
- trueif all elements in the given array are equal to the given value.
 
- 
allEqualspublic static boolean allEquals(float[] array, float value) Returnstrueif all values in the specified array are equal to the specified value, which may beFloat.NaN.- Parameters:
- array- the array to check.
- value- the expected value.
- Returns:
- trueif all elements in the given array are equal to the given value.
 
- 
allEqualspublic static boolean allEquals(int[] array, int value) Returnstrueif all values in the specified array are equal to the specified value.- Parameters:
- array- the array to check.
- value- the expected value.
- Returns:
- trueif all elements in the given array are equal to the given value.
- Since:
- 1.2
 
- 
containsIgnoreCaseReturnstrueif the specified array contains the specified value, ignoring case. This method should be used only for very small arrays.- Parameters:
- array- the array to search in. May be- null.
- value- the value to search.
- Returns:
- trueif the array is non-null and contains the given value, or- falseotherwise.
 
- 
containsIdentityReturnstrueif the specified array contains the specified reference. The comparisons are performed using the==operator.This method should be used only for very small arrays, or for searches to be performed only once, because it performs a linear search. If more than one search need to be done on the same array, consider using IdentityHashMapinstead.- Parameters:
- array- the array to search in. May be- nulland may contains null elements.
- value- the value to search. May be- null.
- Returns:
- trueif the array is non-null and contains the value (which may be null), or- falseotherwise.
 
- 
containsReturnstrueif the specified array contains the specified value. The comparisons are performed using theObject.equals(Object)method.This method should be used only for very small arrays, or for searches to be performed only once, because it performs a linear search. If more than one search need to be done on the same array, consider using HashSetinstead.- Parameters:
- array- the array to search in. May be- nulland may contains null elements.
- value- the value to search. May be- null.
- Returns:
- trueif the array is non-null and contains the value (which may be null), or- falseotherwise.
- See Also:
 
- 
intersectsReturnstrueif at least one element in the first array is equals to an element in the second array. The element doesn't need to be at the same index in both array.This method should be used only for very small arrays since it may be very slow. If the arrays are large or if an array will be involved in more than one search, consider using HashSetinstead.- Parameters:
- array1- the first array, or- null.
- array2- the second array, or- null.
- Returns:
- trueif both array are non-null and have at least one element in common.
- See Also:
 
- 
concatenateReturns the concatenation of all given arrays. This method performs the following checks:- If the arraysargument isnullor contains onlynullelements, then this method returnsnull.
- Otherwise if the arraysargument contains exactly one non-null array with a length greater than zero, then that array is returned. It is not copied.
- Otherwise a new array with a length equals to the sum of the length of every non-null arrays is created, and the content of non-null arrays are appended in the new array in declaration order.
 - Type Parameters:
- T- the type of arrays.
- Parameters:
- arrays- the arrays to concatenate, or- null.
- Returns:
- the concatenation of all non-null arrays (may be a direct reference to one
         of the given array if it can be returned with no change), or null.
- See Also:
 
- If the 
- 
unionOfSortedpublic static int[] unionOfSorted(int[] array1, int[] array2) Returns the union of two sorted arrays. The input arrays shall be sorted in strictly increasing order. The output array is the union of the input arrays without duplicated values, with elements sorted in strictly increasing order.Recommended assertionsCallers are encouraged to place the following assertions before calls to this method, using theisSorted(int[], boolean)andArrays.toString(int[])methods:assert isSorted(array1, true) : toString(array1); assert isSorted(array2, true) : toString(array2); - Parameters:
- array1- the first array, or- null.
- array2- the second array, or- null.
- Returns:
- the union of the given array without duplicated values, or nullif the two given arrays were null. May be one of the given arrays.
- See Also:
 
 
-