Difference between isEmpty and isBlank of StringUtils

There are isEmpty and isBlank functions that are often used in StringUtils, but I sometimes forget the difference, so make a note. isEmpty seems to return only empty strings as true.

qiita.java


package com.example.test;

import java.util.ArrayList;
import java.util.List;
import org.apache.commons.collections4.*;

import org.apache.commons.lang3.StringUtils;
import org.junit.Test;

public class BlankTest {

	@Test
	public void test() {
		System.out.println("Empty string= " + StringUtils.isBlank(""));
		System.out.println("Whitespace character= " + StringUtils.isBlank(" "));
		System.out.println("Double-byte white space= " + StringUtils.isBlank(" "));
		System.out.println("Tab whitespace character= " + StringUtils.isBlank("\t"));
		System.out.println("Empty string= " + StringUtils.isEmpty(""));
		System.out.println("Whitespace character=" + StringUtils.isEmpty(" "));
		System.out.println("Double-byte white space=" + StringUtils.isEmpty(" "));
		System.out.println("Tab whitespace character=" + StringUtils.isEmpty("\t"));				
	}

}

Execution result Empty string = true Whitespace = true Double-byte white space = true Tab whitespace = true Empty string = true Whitespace = false Double-byte white space = false Tab whitespace = false

Recommended Posts

Difference between isEmpty and isBlank of StringUtils
Difference between addPanel and presentModally of FloatingPanel
Difference between vh and%
Difference between i ++ and ++ i
Difference between member and collection of rails routes.rb
Difference between product and variant
Difference between redirect_to and render
[Java] Difference between == and equals
Difference between puts and print
Difference between redirect_to and render
Difference between CUI and GUI
Difference between variables and instance variables
Difference between mockito-core and mockito-all
Difference between class and instance
Difference between bundle and bundle install
Difference between ArrayList and LinkedList
Difference between render and redirect_to
Difference between List and ArrayList
Difference between .bashrc and .bash_profile
Difference between StringBuilder and StringBuffer
Difference between render and redirect_to
Difference between render and redirect_to
[Docker-compose] Difference between env_file and environment. Priority of environment variable application
[Ruby] About the difference between 2 dots and 3 dots of range object.
[Java] Difference between assignment of basic type variable and assignment of reference type variable
[Java] Difference between Stack Overflow Error and Out Of Memory Error
[Ruby] Difference between get and post
Difference between instance method and class method
Difference between render method and redirect_to
Difference between interface and abstract class
Difference between == operator and equals method
[Java] Difference between Hashmap and HashTable
[Terminal] Difference between irb and pry
JavaServlet: Difference between executeQuery and executeUpdate
[Ruby] Difference between is_a? And instance_of?
Difference between == operator and eqals method
Rough difference between RSpec and minitest
[Rails] Difference between find and find_by
Understand the difference between each_with_index and each.with_index
Difference between instance variable and class variable
[JAVA] Difference between abstract and interface
Difference between Thymeleaf @RestController and @Controller
Difference between Stream map and flatMap
[Java] Difference between array and ArrayList
Difference between primitive type and reference type
Difference between string.getByte () and Hex.decodeHex (string.toCharaArray ())
[Java] Difference between Closeable and AutoCloseable
[Java] Difference between StringBuffer and StringBuilder
[Java] Difference between length, length () and size ()
[rails] Difference between redirect_to and render
[Android] Difference between finish (); and return;
Difference between byCharWrapping and byWordWrapping of UI Label in Japanese display
Note: Difference between Ruby "p" and "puts"
Difference between final and Immutable in Java
Difference between Ruby instance variable and local variable
Difference between pop () and peek () in stack
Differences between preface and postfix of operators
Difference between getText () and getAttribute () in Selenium
About the difference between irb and pry
Difference between "|| =" and "instance_variable_defined?" In Ruby memoization
Difference between EMPTY_ELEMENTDATA and DEFAULTCAPACITY_EMPTY_ELEMENTDATA in ArrayList