LoginSignup
0
0

More than 1 year has passed since last update.

【Java】List・Map のnull または空のチェック CollectionUtils.isEmpty

Posted at

List・Mapのnull または 空チェックには CollectionUtils.isEmpty が便利です。

(例)1

Test1.java
package jp.co;

import java.util.List;
import org.springframework.util.CollectionUtils;
import java.util.ArrayList;

public class Test1 {
    public static void main(String[] args) {
        List<String> strList = new ArrayList<>();
        boolean trueOrFalse1 = CollectionUtils.isEmpty(strList); // trueOrFalse1 = true

        strList.add("1つ追加");
        boolean trueOrFalse2 = CollectionUtils.isEmpty(strList); // trueOrFalse2 = false

        strList = null;
        boolean trueOrFalse3 = CollectionUtils.isEmpty(strList); // trueOrFalse3 = true
    }
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0