public class UArrayUtil extends Object
Modifier and Type | Field and Description |
---|---|
static int |
INDEX_NOT_FOUND
数组中元素未找到的下标,值为-1
|
Constructor and Description |
---|
UArrayUtil() |
Modifier and Type | Method and Description |
---|---|
static <T> T[] |
append(T[] buffer,
T... newElements)
将新元素添加到已有数组中
添加新元素会生成一个新的数组,不影响原数组 |
static <T> T |
clone(T obj)
克隆数组,如果非数组返回
null |
static boolean |
contains(char[] array,
char value)
数组中是否包含元素
|
static <T> boolean |
contains(T[] array,
T value)
数组中是否包含元素
|
static Object |
copy(Object src,
Object dest,
int length)
包装
System.arraycopy(Object, int, Object, int, int) 数组复制,缘数组和目标数组都是从位置0开始复制 |
static Class<?> |
getComponentType(Object array)
获取数组对象的元素类型
|
static <T> boolean |
hasNull(T... array)
是否包含
null 元素 |
static int |
indexOf(char[] array,
char value)
返回数组中指定元素所在位置,未找到返回
INDEX_NOT_FOUND |
static <T> int |
indexOf(T[] array,
Object value)
返回数组中指定元素所在位置,未找到返回
INDEX_NOT_FOUND |
static <T> Object |
insert(Object array,
int index,
T... newElements)
将新元素插入到到已有数组中的某个位置
添加新元素会生成一个新的数组,不影响原数组 如果插入位置为为负数,从原数组从后向前计数,若大于原数组长度,则空白处用null填充 |
static <T> T[] |
insert(T[] buffer,
int index,
T... newElements)
将新元素插入到到已有数组中的某个位置
添加新元素会生成一个新的数组,不影响原数组 如果插入位置为为负数,从原数组从后向前计数,若大于原数组长度,则空白处用null填充 |
static boolean |
isArray(Object obj)
对象是否为数组对象
|
static <T> boolean |
isEmpty(T... array)
数组是否为空
|
static <T> boolean |
isNotEmpty(T... array)
数组是否为非空
|
static String |
join(Object array,
CharSequence conjunction)
以 conjunction 为分隔符将数组转换为字符串
|
static <T> String |
join(T[] array,
CharSequence conjunction)
以 conjunction 为分隔符将数组转换为字符串
|
static <T> String |
join(T[] array,
CharSequence conjunction,
String prefix,
String suffix)
以 conjunction 为分隔符将数组转换为字符串
|
static int |
length(Object array)
获取数组长度
如果参数为 null ,返回0 |
static byte |
max(byte... numberArray)
取最大值
|
static char |
max(char... numberArray)
取最大值
|
static double |
max(double... numberArray)
取最大值
|
static float |
max(float... numberArray)
取最大值
|
static int |
max(int... numberArray)
取最大值
|
static long |
max(long... numberArray)
取最大值
|
static short |
max(short... numberArray)
取最大值
|
static <T extends Comparable<? super T>> |
max(T[] numberArray)
取最大值
|
static double |
min(double... numberArray)
取最小值
|
static float |
min(float... numberArray)
取最小值
|
static int |
min(int... numberArray)
取最小值
|
static long |
min(long... numberArray)
取最小值
|
static short |
min(short... numberArray)
取最小值
|
static <T extends Comparable<? super T>> |
min(T[] numberArray)
取最小值
|
static <T> T[] |
newArray(Class<?> componentType,
int newSize)
新建一个空数组
|
static char[] |
reverse(char[] array)
反转数组,会变更原数组
|
static char[] |
reverse(char[] array,
int startIndexInclusive,
int endIndexExclusive)
反转数组,会变更原数组
|
static String |
toString(Object obj)
数组或集合转String
|
static Object[] |
wrap(Object obj)
包装数组对象
|
public static final int INDEX_NOT_FOUND
public static <T> boolean isEmpty(T... array)
T
- 数组元素类型array
- 数组public static <T> boolean isNotEmpty(T... array)
T
- 数组元素类型array
- 数组public static <T> boolean hasNull(T... array)
null
元素T
- 数组元素类型array
- 被检查的数组null
元素public static <T extends Comparable<? super T>> T min(T[] numberArray)
T
- 元素类型numberArray
- 数字数组public static long min(long... numberArray)
numberArray
- 数字数组public static int min(int... numberArray)
numberArray
- 数字数组public static short min(short... numberArray)
numberArray
- 数字数组public static double min(double... numberArray)
numberArray
- 数字数组min(double...)
public static float min(float... numberArray)
numberArray
- 数字数组public static <T extends Comparable<? super T>> T max(T[] numberArray)
T
- 元素类型numberArray
- 数字数组public static long max(long... numberArray)
numberArray
- 数字数组public static int max(int... numberArray)
numberArray
- 数字数组public static short max(short... numberArray)
numberArray
- 数字数组public static char max(char... numberArray)
numberArray
- 数字数组public static byte max(byte... numberArray)
numberArray
- 数字数组public static double max(double... numberArray)
numberArray
- 数字数组public static float max(float... numberArray)
numberArray
- 数字数组public static boolean isArray(Object obj)
obj
- 对象null
返回falsepublic static String toString(Object obj)
obj
- 集合或数组对象public static <T> String join(T[] array, CharSequence conjunction)
T
- 被处理的集合array
- 数组conjunction
- 分隔符public static <T> String join(T[] array, CharSequence conjunction, String prefix, String suffix)
T
- 被处理的集合array
- 数组conjunction
- 分隔符prefix
- 每个元素添加的前缀,null表示不添加suffix
- 每个元素添加的后缀,null表示不添加public static String join(Object array, CharSequence conjunction)
array
- 数组conjunction
- 分隔符public static boolean contains(char[] array, char value)
array
- 数组value
- 被检查的元素public static int indexOf(char[] array, char value)
INDEX_NOT_FOUND
array
- 数组value
- 被检查的元素INDEX_NOT_FOUND
public static Object[] wrap(Object obj)
obj
- 对象,可以是对象数组或者基本类型数组UtilException
- 对象为非数组public static char[] reverse(char[] array, int startIndexInclusive, int endIndexExclusive)
array
- 数组,会变更startIndexInclusive
- 其实位置(包含)endIndexExclusive
- 结束位置(不包含)public static char[] reverse(char[] array)
array
- 数组,会变更public static <T> T clone(T obj)
null
T
- 数组元素类型obj
- 数组对象public static <T> T[] newArray(Class<?> componentType, int newSize)
T
- 数组元素类型componentType
- 元素类型newSize
- 大小public static int length(Object array) throws IllegalArgumentException
null
,返回0
UArrayUtil.length(null) = 0 UArrayUtil.length([]) = 0 UArrayUtil.length([null]) = 1 UArrayUtil.length([true, false]) = 2 UArrayUtil.length([1, 2, 3]) = 3 UArrayUtil.length(["a", "b", "c"]) = 3
array
- 数组对象IllegalArgumentException
- 如果参数不为数组,抛出此异常Array.getLength(Object)
public static <T> Object insert(Object array, int index, T... newElements)
T
- 数组元素类型array
- 已有数组index
- 插入位置,此位置为对应此位置元素之前的空档newElements
- 新元素public static <T> T[] insert(T[] buffer, int index, T... newElements)
T
- 数组元素类型buffer
- 已有数组index
- 插入位置,此位置为对应此位置元素之前的空档newElements
- 新元素@SafeVarargs public static <T> T[] append(T[] buffer, T... newElements)
T
- 数组元素类型buffer
- 已有数组newElements
- 新元素public static Class<?> getComponentType(Object array)
array
- 数组对象public static <T> boolean contains(T[] array, T value)
T
- 数组元素类型array
- 数组value
- 被检查的元素public static <T> int indexOf(T[] array, Object value)
INDEX_NOT_FOUND
T
- 数组类型array
- 数组value
- 被检查的元素INDEX_NOT_FOUND
public static Object copy(Object src, Object dest, int length)
System.arraycopy(Object, int, Object, int, int)
src
- 源数组dest
- 目标数组length
- 拷贝数组长度Copyright © 2020. All rights reserved.