For the Java language, everything is an object. Objects in the real world are abstractly reflected in the programming world, and an object represents a specific operation. Each object ultimately forms a complete program design. These objects can exist independently or can be inherited from other objects. Objects transfer information through interaction to realize program development.
Java is an object-oriented programming language, and objects are the core of object-oriented programming. The so-called objects are entities in the real world. There is a one-to-one correspondence between objects and entities. That is to say, every entity in the real world is an object and it is a specific concept.
Java method to determine whether the object is empty:
1. Located in StringUtils under the org.apache.commons.lang package
public class StringUtilsTest { public static void main(String[] args) { System.out.println(StringUtils.isEmpty(null)); //true System.out.println(StringUtils.isEmpty("")); //true System.out.println(StringUtils.isEmpty(" ")); //false 注意在空格作非空处理 System.out.println(StringUtils.isEmpty("string"));//false System.out.println(StringUtils.isBlank(null)); //true System.out.println(StringUtils.isBlank("")); //true System.out.println(StringUtils.isBlank(" ")); //true System.out.println(StringUtils.isBlank(" ")); //true } }
2. Located in the org.springframework.util package Under StringUtils
StringUtils class under the org.apache.commons.lang3 package, the method parameter to determine whether it is empty is the character sequence class, which is the String type StringUtils.isEmpty(Object str);
The parameter under the org.springframework.util package is the Object class, which means it can not only determine the String type, but also other types, such as Long and other types. 12345
3. Determine whether the List is empty
if (tocoupleDOList != null && !tocoupleDOList.isEmpty()) { }
4. ObjectUtils located under the org.apache.commons.lang package determines whether the object is empty
More For java knowledge, please pay attention to the java basic tutorial column.
The above is the detailed content of Java determines whether an object is empty. For more information, please follow other related articles on the PHP Chinese website!