Check processing is indispensable for creating a program, but here we have summarized the check processing in Java.
Environment: Spring Framework
import java.util.Objects;
class Check {
void execute() {
// message == null
if (Objects.isNull(message)) {
}
// message != null
if (Objects.nonNull(message)) {
}
// message ==Throw a NullPointerException if null
Objects.requireNonNull(message);
}
}
import org.springframework.util.StringUtils;
class Check {
void execute() {
// (message == null || "".equals(message))
if (StringUtils.isEmpty(message)) {
}
// (str != null && !str.isEmpty())
if (StringUtils.hasLength(message)) {
}
}
}
import org.springframework.util.CollectionUtils;
class Check {
void execute() {
List<String> list = new ArrayList<>();
list.add("Hello");
list.add("World");
// (list == null || list.isEmpty())
if (CollectionUtils.isEmpty(list)) {
}
}
}
Recommended Posts