Top Description Constructors Methods
org.glassfish.grizzly.utils

public final Class ArrayUtils

extends Object
Class Inheritance
Imports
java.lang.reflect.Array, java.util.Arrays

Set of utility methods to work with Arrays.
Author
Alexey Stashok

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public static <
type of the array element
T
>
T[]

Returns:

array, which will contain the new element. Either new array instance, if passed array didn't contain the element, or the same array instance, if the element is already present in the array.
addUnique
(T[]
array
array
,
T
element to add
element
)

Add unique element to the array.

public static <
type of the array element
T
>
T[]

Returns:

array, which will contain the new element. Either new array instance, if passed array didn't contain the element, or the same array instance, if the element is already present in the array.
addUnique
(final T[]
array
array
,
final T
element to add
element
,
final boolean
if passed element is equal to some element in the array then depending on this parameter it will be replaced or not with the passed element.
replaceElementIfEquals
)

Add unique element to the array.

public static int
binarySearch(final int[] a, final int fromIndex, final int toIndex, final int key)

public static <
type of the array element
T
>
int

Returns:

element's index, or -1 if element wasn't found.
indexOf
(T[]
array
array
,
Object
the element to look for.
element
)

Return the element index in the array.

public static <
type of the array element
T
>
T[]

Returns:

array, which won't contain the element. Either new array instance, if passed array contains the element, or the same array instance, if the element wasn't present in the array. null will be returned if the last element was removed from the passed array.
remove
(T[]
array
array
,
Object
the element to remove
element
)

Removes the element from the array.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

ArrayUtilsback to summary
public ArrayUtils()

Method Detail

addUniqueback to summary
public static <T> T[] addUnique(T[] array, T element)

Add unique element to the array.

Parameters
<T>
type of the array element
array:T[]

array

element:T

element to add

Returns:T[]

array, which will contain the new element. Either new array instance, if passed array didn't contain the element, or the same array instance, if the element is already present in the array.

addUniqueback to summary
public static <T> T[] addUnique(final T[] array, final T element, final boolean replaceElementIfEquals)

Add unique element to the array.

Parameters
<T>
type of the array element
array:T[]

array

element:T

element to add

replaceElementIfEquals:boolean

if passed element is equal to some element in the array then depending on this parameter it will be replaced or not with the passed element.

Returns:T[]

array, which will contain the new element. Either new array instance, if passed array didn't contain the element, or the same array instance, if the element is already present in the array.

binarySearchback to summary
public static int binarySearch(final int[] a, final int fromIndex, final int toIndex, final int key)
indexOfback to summary
public static <T> int indexOf(T[] array, Object element)

Return the element index in the array.

Parameters
<T>
type of the array element
array:T[]

array

element:Object

the element to look for.

Returns:int

element's index, or -1 if element wasn't found.

removeback to summary
public static <T> T[] remove(T[] array, Object element)

Removes the element from the array.

Parameters
<T>
type of the array element
array:T[]

array

element:Object

the element to remove

Returns:T[]

array, which won't contain the element. Either new array instance, if passed array contains the element, or the same array instance, if the element wasn't present in the array. null will be returned if the last element was removed from the passed array.

Annotations
@SuppressWarnings:unchecked