public class ArrayUtils extends Object
Modifier and Type | Method and Description |
---|---|
static boolean |
contains(int[] array,
int elem)
Returns true if the given
array contains the given element. |
static <T> boolean |
contains(T[] array,
T elem)
Returns true if the given
array contains the given element. |
static int[] |
convertStringListToIntArray(List<String> list,
String[] convertFrom,
int[] convertTo)
Create an
int[] from the List<> by using convertFrom and
convertTo as a one-to-one map (via the index). |
static List<Integer> |
convertStringListToIntList(List<String> list,
String[] convertFrom,
int[] convertTo)
Create an
List<Integer> from the List<> by using convertFrom and
convertTo as a one-to-one map (via the index). |
static int |
getArrayIndex(int[] array,
int needle)
Return the index of
needle in the array , or else -1 |
static <T> int |
getArrayIndex(T[] array,
T needle)
Return the index of
needle in the array , or else -1 |
static int[] |
toIntArray(List<Integer> list)
Convert the list of integers in
list to an int array. |
public static <T> int getArrayIndex(T[] array, T needle)
needle
in the array
, or else -1
public static int getArrayIndex(int[] array, int needle)
needle
in the array
, or else -1
public static int[] convertStringListToIntArray(List<String> list, String[] convertFrom, int[] convertTo)
int[]
from the List<>
by using convertFrom
and
convertTo
as a one-to-one map (via the index).
Strings not appearing in convertFrom
are ignored (with a logged warning);
strings appearing in convertFrom
but not convertTo
are silently
dropped.
list
- Source list of stringsconvertFrom
- Conversion list of stringsconvertTo
- Conversion list of intsconvertTo
or null
if list
was null
public static List<Integer> convertStringListToIntList(List<String> list, String[] convertFrom, int[] convertTo)
List<Integer>
from the List<>
by using convertFrom
and
convertTo
as a one-to-one map (via the index).
Strings not appearing in convertFrom
are ignored (with a logged warning);
strings appearing in convertFrom
but not convertTo
are silently
dropped.
list
- Source list of stringsconvertFrom
- Conversion list of stringsconvertTo
- Conversion list of intsconvertTo
or null
if list
was null
public static int[] toIntArray(List<Integer> list)
list
to an int
array.
Every element in list
must be non-null
.
list
- a list of non-null
integerslist
NullPointerException
- if any of the elements in list
were null
public static boolean contains(int[] array, int elem)
array
contains the given element.array
- array
to check for elem
elem
- elem
to test fortrue
if the given element is containedpublic static <T> boolean contains(T[] array, T elem)
array
contains the given element.array
- array
to check for elem
elem
- elem
to test fortrue
if the given element is contained