[Java] Differences Between StringUtils.isEmpty and StringUtils.isBlank

Tadashi Shigeoka ·  Fri, November 18, 2011

Java has similar methods called isEmpty and isBlank, so I researched their differences and would like to share them.

Java

To put it simply:

  • isBlank: Returns true for half-width/full-width whitespace characters
  • isEmpty: Returns false for half-width/full-width whitespace characters
System.out.println("isBlank(null):" + StringUtils.isBlank(null));
System.out.println("isBlank(\\"\\"):" + StringUtils.isBlank(""));
System.out.println("isBlank(\\" \\"):" + StringUtils.isBlank(" "));
System.out.println("isBlank(\\" \\"):" + StringUtils.isBlank(" "));//Full-width whitespace character

System.out.println(“isEmpty(null):” + StringUtils.isEmpty(null)); System.out.println(“isEmpty(\”\”):” + StringUtils.isEmpty("")); System.out.println(“isEmpty(\” \”):” + StringUtils.isEmpty(” ”)); System.out.println(“isEmpty(\” \”):” + StringUtils.isEmpty(” ”));//Full-width whitespace character

Execution results

isBlank(null):true
isBlank(""):true
isBlank(" "):true
isBlank(" "):true

isEmpty(null):true
isEmpty(""):true
isEmpty(" "):false
isEmpty(" "):false

That’s all from the Java Gemba.