StringUtils.isNotBlank() VS StringUtils.isNotEmpty() in Java

  StringUtils.isNotBlank() VS StringUtils.isNotEmpty() in Java

isNotBlank

public static boolean isNotBlank(String str)

Checks if a String is not empty (“”), not null and not whitespace only.

 

StringUtils.isNotBlank(null) = false

StringUtils.isNotBlank(“”) = false

StringUtils.isNotBlank(” “) = false

StringUtils.isNotBlank(“java”) = true

StringUtils.isNotBlank(“java  “) = true

 

Parameters:

str – the String to check

Returns:true if the String is not empty and not null and not whitespace

isNotEmpty

public static boolean isNotEmpty(String str)

Checks if a String is not empty (“”) and not null.

StringUtils.isNotEmpty(null)      = false
StringUtils.isNotEmpty(“”)        = false
StringUtils.isNotEmpty(” “)       = true
StringUtils.isNotEmpty(“java”)     = true
StringUtils.isNotEmpty(“java  “) = true
Parameters:
str – the String to check, may be null

Returns:
true if the String is not empty and not null

Related Post:

Leave a Reply

Your email address will not be published. Required fields are marked *

− 7 = 2