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