public class ArrayUtil
extends java.lang.Object
Arrays
.Modifier and Type | Method and Description |
---|---|
static <T,C extends java.util.Collection<? super T>> |
collectMatching(T[] a,
java.util.function.Predicate<? super T> p,
C c)
Appends all of the elements in the given array that match the given
predicate to the end of the given collection, in the order they follow
in the array.
|
static <T> java.util.List<T> |
concat(T[] a,
java.util.Collection<? extends T> b)
Returns a list that represents the concatenation of the given collection
to the end of the given array.
|
static boolean |
contains(java.lang.Object[] a,
java.lang.Object o)
Returns whether the given array contains the given element.
|
static <T> boolean |
containsMatching(T[] a,
java.util.function.Predicate<? super T> p)
Returns whether the given array contains an element matching the given
predicate.
|
static <T> java.util.List<T> |
elementsOfType(java.lang.Object[] a,
java.lang.Class<? extends T>... types)
Returns a list of all of the elements in the given array that have any
of the given types, in the order the elements follow in the given array.
|
static boolean |
hasElementsNotOfType(java.lang.Object[] a,
java.lang.Class<?>... types)
Returns whether the given array contains an element that has none of the
given types.
|
static boolean |
hasElementsOfType(java.lang.Object[] a,
java.lang.Class<?>... types)
Returns whether the given array contains an element that has any of the
given types.
|
static boolean |
hasOnlyElementsOfType(java.lang.Object[] a,
java.lang.Class<?>... types)
Returns whether all of the elements in the given array have any of the
given types.
|
static int |
indexOf(java.lang.Object[] a,
java.lang.Object o)
Returns the index of the first occurrence of the given element in the
given array, or -1 if the array does not contain the element.
|
static <T> int |
indexOfMatching(T[] a,
java.util.function.Predicate<? super T> p)
Returns the index of the first occurrence of an element matching the
given predicate in the given array, or -1 if the array does not contain
an element matching the predicate.
|
static int |
lastIndexOf(java.lang.Object[] a,
java.lang.Object o)
Returns the index of the last occurrence of the given element in the
given array, or -1 if the array does not contain the element.
|
static <T> int |
lastIndexOfMatching(T[] a,
java.util.function.Predicate<? super T> p)
Returns the index of the last occurrence of an element matching the
given predicate in the given array, or -1 if the array does not contain
an element matching the predicate.
|
static <T> java.util.Set<T> |
setMinus(T[] a,
java.util.Collection<?> b)
Returns a set of elements that are present in the given array but are
absent in the given collection.
|
static <T> java.util.Set<T> |
union(T[] a,
java.util.Collection<? extends T> b)
Returns a set of elements that are present in either the given array
or the given collection.
|
public static boolean contains(java.lang.Object[] a, java.lang.Object o)
true
iff the array contains at least
one element e
such that Objects.equals(e, o)
.a
- the array (not null
)o
- the element whose presence in the given array is to be tested
(may be null
)true
if the given array contains the given element,
and false
otherwisepublic static int indexOf(java.lang.Object[] a, java.lang.Object o)
i
such that
Objects.equals(o, a[i])
, or -1 if there is no such index.a
- the array (not null
)o
- the element to search for in the given array
(may be null
)public static int lastIndexOf(java.lang.Object[] a, java.lang.Object o)
i
such that
Objects.equals(o, a[i])
, or -1 if there is no such index.a
- the array (not null
)o
- the element to search for in the given array
(may be null
)public static <T> boolean containsMatching(T[] a, java.util.function.Predicate<? super T> p)
true
iff the array contains
at least one element e
such that p.test(e)
.a
- the array (not null
)p
- the predicate to match (not null
)true
if the given array contains an element matching
the given predicate, and false
otherwisepublic static <T> int indexOfMatching(T[] a, java.util.function.Predicate<? super T> p)
i
such that p.test(a[i])
, or -1 if there is no
such index.a
- the array (not null
)p
- the predicate to match (not null
)public static <T> int lastIndexOfMatching(T[] a, java.util.function.Predicate<? super T> p)
i
such that p.test(a[i])
, or -1 if there is no
such index.a
- the array (not null
)p
- the predicate to match (not null
)public static <T,C extends java.util.Collection<? super T>> C collectMatching(T[] a, java.util.function.Predicate<? super T> p, C c)
a
- the array (not null
)p
- the predicate to match (not null
)c
- the collection to add matching elements to (not null
)c
@SafeVarargs public static <T> java.util.List<T> elementsOfType(java.lang.Object[] a, java.lang.Class<? extends T>... types)
a
- the array (not null
)types
- at least one type (each type not null
)null
)public static boolean hasElementsOfType(java.lang.Object[] a, java.lang.Class<?>... types)
a
- the array (not null
)types
- at least one type (each type not null
)true
if the given array contains an element that has
any of the given types, and false
otherwisepublic static boolean hasElementsNotOfType(java.lang.Object[] a, java.lang.Class<?>... types)
a
- the array (not null
)types
- at least one type (each type not null
)true
if the given array contains an element that has
none of the given types, and false
otherwisepublic static boolean hasOnlyElementsOfType(java.lang.Object[] a, java.lang.Class<?>... types)
a
- the array (not null
)types
- at least one type (each type not null
)true
if all of the elements in the given array have
any of the given types, and false
otherwisepublic static <T> java.util.List<T> concat(T[] a, java.util.Collection<? extends T> b)
a
- the array (not null
)b
- the collection that is concatenated to the end of the given array
(not null
)null
)public static <T> java.util.Set<T> union(T[] a, java.util.Collection<? extends T> b)
a
- the array to "add" elements to (not null
)b
- the collection of elements to "add" (not null
)null
)public static <T> java.util.Set<T> setMinus(T[] a, java.util.Collection<?> b)
a
- the array to "subtract" elements from (not null
)b
- the collection of elements to "subtract" (not null
)null
)Copyright (c) 2014, 2020 1C-Soft LLC and others. Made available under the Eclipse Public License 2.0