Java check process

Introduction

Check processing is indispensable for creating a program, but here we have summarized the check processing in Java.

Prerequisites

Environment: Spring Framework

Check processing

General object check

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);
    }
}

String check

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)) {
        }

    }
}

Check Collection


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

Java check process
Check Java toString () implementation
Check the options set for the running Java process
Check Java9 Interface private methods
Shell to kill Java process
Java
Check https connection in Java
External process execution in Java
Java
[Java] Input to stdin of Process
[Java] Element existence check with Stream
thread safe process in java language
Check Java parameters in Kubernetes pods
[Java] Date period duplication check sample
Run an external process in Java
How to check Java installed on Mac
Studying Java ―― 3
[Java] array
Java protected
[Java] Annotation
[Java] Module
Java array
Studying Java ―― 9
Java scratch scratch
Java tips, tips
Java methods
Java method
java (constructor)
Java array
[Java] ArrayDeque
java (override)
java (method)
Java Day 2018
Java string
Check the contents of the Java certificate store
java (array)
Java static
Java serialization
java beginner 4
JAVA paid
Studying Java ―― 4
java shellsort
[Java] compareTo
java reflexes
java (interface)
Java memorandum
☾ Java / Collection
Java array
Studying Java ―― 1
[Java] Array
[Java] Polymorphism
Java review
java framework
Java features
[Java] Inheritance
FastScanner Java
Java features
java beginner 3
Java memo
java (encapsulation)
Java inheritance