Skip to content

Commit 472fbf9

Browse files
committed
feat: 添加 CollectUtil 集合工具类
1 parent 97b562b commit 472fbf9

2 files changed

Lines changed: 55 additions & 0 deletions

File tree

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package top.cadecode.common.util;
2+
3+
import java.util.Arrays;
4+
5+
/**
6+
* @author Cade Li
7+
* @date 2021/12/4
8+
* @description 集合工具类
9+
*/
10+
public class CollectUtil {
11+
12+
/**
13+
* 判断数组是否为空
14+
*
15+
* @param objects 数组
16+
* @return boolean
17+
*/
18+
public static boolean isEmpty(Object[] objects) {
19+
return objects == null || objects.length == 0;
20+
}
21+
22+
/**
23+
* 判断数组是否包含指定元素
24+
*
25+
* @param objects 数组
26+
* @param o 元素
27+
* @return boolean
28+
*/
29+
public static boolean contains(Object[] objects, Object o) {
30+
if (objects == null || objects.length == 0) {
31+
return false;
32+
}
33+
return Arrays.asList(objects).contains(o);
34+
}
35+
36+
37+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package top.cadecode.common.util;
2+
3+
import org.junit.jupiter.api.Test;
4+
5+
/**
6+
* @author Cade Li
7+
* @date 2021/12/4
8+
* @description ToDo
9+
*/
10+
public class CollectUtilTest {
11+
12+
@Test
13+
public void arrayContains() {
14+
Integer[] arr = {1, 2, 3};
15+
boolean contains = CollectUtil.contains(arr, 3);
16+
System.out.println(contains);
17+
}
18+
}

0 commit comments

Comments
 (0)