Skip to content

Commit c4dd542

Browse files
author
zihluwang
committed
feat: check whether a collection is empty or not
1 parent bcaff32 commit c4dd542

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

common-toolbox/src/main/java/com/onixbyte/common/util/CollectionUtil.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,4 +112,25 @@ public static <T, C extends Collection<T>> List<C> chunk(
112112
return result;
113113
}
114114

115+
/**
116+
* Check whether a given collection is not empty.
117+
*
118+
* @param collection the collection to be checked
119+
* @return {@code true} if provided collection is not null and not empty,
120+
* {@code false} otherwise
121+
*/
122+
public static boolean notEmpty(Collection<?> collection) {
123+
return Objects.nonNull(collection) && !collection.isEmpty();
124+
}
125+
126+
/**
127+
* Check whether a given collection is empty.
128+
*
129+
* @param collection the collection to be checked
130+
* @return {@code true} if provided collection is null or is empty, {@code false} otherwise
131+
*/
132+
public static boolean isEmpty(Collection<?> collection) {
133+
return Objects.isNull(collection) || collection.isEmpty();
134+
}
135+
115136
}

0 commit comments

Comments
 (0)