public class ArrayUtils extends Object
| Modifier and Type | Field and Description |
|---|---|
static int |
INDEX_OF_NOT_FOUND
未找到要检索的值
|
| Constructor and Description |
|---|
ArrayUtils() |
| Modifier and Type | Method and Description |
|---|---|
static <T> T[] |
append(T[] array,
T element)
添加指定元素到给定数组的末尾,并返回这个新的数组。 Append the given element to the end of
given array.
|
static <T> T[] |
append(T[] array0,
T[] array1)
添加指定数组到给定数组的末尾,并返回这个新的数组。Append the given array1 to the end of given
array0.
|
static <T> T[] |
append(T element,
T[] array)
添加指定元素到给定数组的头位置,并返回这个新的数组。Append the given element to the start of the
given array.
|
static <T> T[] |
buildArray(Class<T> type,
int size,
T defaultValue)
新建数组。Returns a new given size length array instance by given type's
wrapper type use default value.
|
static <T> boolean |
contains(T[] array,
T element)
判定指定的数组是否包含指定的元素。 Returns true if this array contains the given element;
false otherwise.
|
static <T> void |
copy(T source,
T target)
复制源数组的数数据到指定数组。如果给定的数组有为空的存在,则不执行任何操作。否则按给定数组中长度最小的长度来复制数据。
|
static <T> void |
copy(T source,
T target,
int sourceStartIndex,
int targetStartIndex,
int copyLength)
按指定的起始位置来复制源数组的数数据到指定数组。
|
static <T> int |
count(T[] array,
T target)
统计数组中包含指定元素的个数。Count how many given target in given array.
|
static <T> T |
getLastElement(T[] array)
返回数组最后一个元素。如果数组为空,返回null.
|
static <T> int |
indexOf(T[] array,
T element)
查找指定元素在给定数组中的索引。 Returns the index within given array of the first
occurrence of the specified element.
If not found any array element equals specified, return -1. |
static boolean |
isArray(Object object)
判定是否为数组。Returns true if given object is an not null array; false
otherwise.
|
static boolean |
isEmpty(Object array)
判定给定的数组是否为空。 Returns true if given object is an not null array and
it is length == 0; false otherwise.
|
static boolean |
isEmpty(Object[] array)
判定给定的数组是否为空。 Returns true if the array is null or empty; false
otherwise.
|
static boolean |
isNotEmpty(Object array)
判定给定的数组是否不为空。 Returns true if given object is an array,and not null
and length > 0; false otherwise.
|
static boolean |
isNotEmpty(Object[] array)
判定给定的数组是否不为空。 Return true if given array is both not null and not
empty;false otherwise.
|
static String |
join(Object[] array,
String separator)
按指定的分割符拼接数组里的元素。
|
static String |
join(Object array,
String separator)
按指定的分割符拼接数组里的元素。
|
static <T> T[] |
remove(T[] array,
T target)
移出给定数组中的所有指定元素。Remove all given target element from given array.
|
static <T> T[] |
subArray(T[] array,
int start)
裁剪数组。Returns a new array if array is not empty and start greater or
equals 0 and less than array length; array self otherwise;
|
static <T> T[] |
subArray(T[] array,
int start,
int end)
裁剪数组。 Returns a new array if array is not empty and start greater or
equals 0 and less than end and end less than array length; array self
otherwise;
|
static <T> T |
subArray(T array,
int start,
int end)
裁剪数组。
|
static <T> T[] |
toArray(Collection<T> collection)
将集合类型转换为数组。
|
static <T> T[] |
toArray(Object source,
Class<T> wrapperType)
将基本数据类型的数组转换成给定封装类型的数组。Convert primitive array to given wrapper type
array.
|
static <T> List<T> |
toList(Object array,
Class<T> wrapperType)
将给定的基本数据数组转换为给定的封装类型的数组。Convert primitive array to given wrapper type
list.
|
static <T> List<T> |
toList(T[] array)
将给定数组转换成List。Convert given array to a list.
|
static <T> Set<T> |
toSet(Object array,
Class<T> wrapperType)
将给定的基本数据类型的数组转换成给定封装数组类型的Set。注意:相同hashCode的元素将只保留一个。Convert primitive
array to given wrapper type set.
|
static <T> Set<T> |
toSet(T[] array)
将给定数组转换成Set。注意:相同hashCode的元素将只保留一个。Convert given array to a set.
|
public static final int INDEX_OF_NOT_FOUND
public static boolean isEmpty(Object[] array)
array - 用来测试的数组。the array to be tested.public static boolean isEmpty(Object array)
array - 用来测试的数组。the array to be tested.public static boolean isNotEmpty(Object[] array)
array - 用来测试的数组。the array to be tested.public static boolean isNotEmpty(Object array)
array - 用来测试的数组。the array to be tested.public static boolean isArray(Object object)
object - 用来测试的数组。the array to be tested.public static <T> boolean contains(T[] array,
T element)
array - 用来测试的数组。the array to be tested.element - 用来测试的元素。the element to be tested.public static <T> int indexOf(T[] array,
T element)
array - 一个不为null的数组。any not null array.element - 任何对象。any object.public static <T> T[] append(T[] array,
T element)
array - 源数组。element - 被添加的元素。public static <T> T[] append(T[] array0,
T[] array1)
array0 - 排在前面的源数组。array1 - 排在后面的源数组。public static <T> T[] append(T element,
T[] array)
element - 被添加的元素。array - 源数组。public static <T> T[] subArray(T[] array,
int start)
array - 源数组。array to be handed.start - 裁剪的起始位置的索引。start index number.public static <T> T subArray(T array,
int start,
int end)
array - 源数组。start - 裁剪的起始位置的索引。end - 裁剪的结束位置的索引。public static <T> T[] subArray(T[] array,
int start,
int end)
array - 源数组。array to be handed.start - 裁剪的起始位置的索引。start index number.end - 裁剪的结束位置的索引。end index number.public static <T> T[] remove(T[] array,
T target)
array - 源数组。 source array.target - 想要被移除的元素。element want to remove.public static <T> int count(T[] array,
T target)
array - 源数组。source array.target - 想要被统计的元素。element want to count.public static <T> T[] buildArray(Class<T> type, int size, T defaultValue)
type - 数组封装类型。the array component type.size - 数组长度。want to build array length.defaultValue - 默认值。the default value of array element.public static <T> void copy(T source,
T target)
source - 源数组。target - 目标数组。public static <T> void copy(T source,
T target,
int sourceStartIndex,
int targetStartIndex,
int copyLength)
以下情况将不会执行任何操作: 1.sourceStartIndex < 0 或 targetStartIndex < 0。 2.sourceStartIndex > source数组的长度,或 sourceStartIndex + copyLength > source数组的长度。 3.targetStartIndex > target数组的长度 或 targetStartIndex + copyLength > target数组的长度。
source - 源数组。target - 目标数组。sourceStartIndex - 源数组的起始位置的索引。targetStartIndex - 目标数组的起始位置的索引。copyLength - 想要复制的元素个数。public static <T> T[] toArray(Collection<T> collection)
collection - 实现了Collection接口的对象。public static <T> T[] toArray(Object source, Class<T> wrapperType)
source - 基本数据类型组成的数组。primitive array...wrapperType - 给定数组元素将封装成的类型。the array element type will covert to given
wrapper type.public static <T> List<T> toList(T[] array)
array - 源数组。source array.public static <T> List<T> toList(Object array, Class<T> wrapperType)
array - 源基本数据数组。source primitive array.wrapperType - 将要转换成的封装类型。the array element type will covert to given wrapper
type.public static <T> Set<T> toSet(T[] array)
array - 源数组。source array.public static <T> Set<T> toSet(Object array, Class<T> wrapperType)
array - 源数组。 source array.wrapperType - 将要转换成的封装类型。the array element type will convert to given
wrapper type.public static <T> T getLastElement(T[] array)
array - 任意数组。public static String join(Object[] array, String separator)
array - 任意数组。separator - 分割符Copyright © 2014. All rights reserved.