File tree Expand file tree Collapse file tree
simple-common/src/main/java/top/cadecode/common/util
simple-web/src/test/java/top/cadecode/common/util Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments