public final class ArrayUtils extends Object
Operations on arrays, primitive arrays (like int[]
) and primitive wrapper arrays (like Integer[]
).
This class tries to handle null
input gracefully. An exception will not be thrown for a null
array
input. However, an Object array that contains a null
element may throw an exception. Each method documents
its behavior.
Modifier and Type | Method and Description |
---|---|
static int[] |
add(int[] array,
int element)
Copies the given array and adds the given element at the end of the new array.
|
static int[] |
add(int[] array,
int index,
int element)
Underlying implementation of add(array, index, element) methods.
|
static boolean |
contains(int[] array,
int valueToFind)
Checks if the value is in the given array.
|
static int |
getArrayIndex(int[] arr,
int value)
Finds the index of the given value in the array.
|
static int |
getArrayMinIndex(int[] arr)
Finds the index of the minimum value in the array.
|
static int[] |
insert(int index,
int[] array,
int... values)
Inserts elements into an array at the given index (starting from zero).
|
static Object |
remove(Object array,
int index)
Removes the element at the specified position from the specified array.
|
static int[] |
removeElements(int[] array,
int... values)
Removes occurrences of specified elements, in specified quantities,
from the specified array.
|
public static int[] add(int[] array, int index, int element)
array
- the array to add the element to, may be null
index
- the position of the new objectelement
- the object to addpublic static int[] insert(int index, int[] array, int... values)
index
- the position within array
to insert the new valuesarray
- the array to insert the values into, may be null
values
- the new values to insert, may be null
IndexOutOfBoundsException
- if array
is provided
and either index < 0
or index > array.length
public static Object remove(Object array, int index)
array
- the array to remove the element from, may not be null
index
- the position of the element to be removedIndexOutOfBoundsException
- if the index is out of range
(index < 0 || index >= array.length), or if the array is null
.public static int[] add(int[] array, int element)
array
- the array to copy and add the element to, may be null
element
- the object to add at the last index of the new arraypublic static boolean contains(int[] array, int valueToFind)
false
if a null
array is passed in.array
- the array to search throughvalueToFind
- the value to findtrue
if the array contains the objectpublic static int[] removeElements(int[] array, int... values)
array
- the array to remove the element from, may be null
values
- the elements to be removedpublic static int getArrayIndex(int[] arr, int value)
arr
- array to search through for the object, may be nullvalue
- to findpublic static int getArrayMinIndex(int[] arr)
arr
- array to search through for the object, may be nullCopyright © 2023 CNES. All rights reserved.