Hutool 是一个 Java 工具包,它提供了很多方便实用的工具类。要判断一个对象是否有一个有值,可以使用 Hutool 的 ObjectUtil 类的 isNotEmpty 方法。

使用示例:

import cn.hutool.core.util.ObjectUtil;

public class Main {
    public static void main(String[] args) {
        String str = "Hello world";
        boolean hasValue = ObjectUtil.isNotEmpty(str);
        System.out.println("hasValue: " + hasValue);  // 输出:hasValue: true

        Integer integer = null;
        hasValue = ObjectUtil.isNotEmpty(integer);
        System.out.println("hasValue: " + hasValue);  // 输出:hasValue: false
    }
}

在上面的示例中,我们首先判断了一个字符串对象 str 是否有值,由于它不为 null 且不为空字符串,所以 hasValue 的值为 true。接着,我们判断了一个整数对象 integer 是否有值,由于它为 null,所以 hasValue 的值为 false

hutool 判断对象是否有一个有值