1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

StringUtilsのisEmptyとisBlankの違い

Posted at

StringUtilsでよく使う関数でisEmptyとisBlankがあるんだけど、違いをたまに忘れてしまうのでメモ。
isEmptyは空文字だけを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("空文字= " + StringUtils.isBlank(""));
		System.out.println("空白文字= " + StringUtils.isBlank(" "));
		System.out.println("全角空白文字= " + StringUtils.isBlank(" "));
		System.out.println("タブ空白文字= " + StringUtils.isBlank("\t"));
		System.out.println("空文字= " + StringUtils.isEmpty(""));
		System.out.println("空白文字=" + StringUtils.isEmpty(" "));
		System.out.println("全角空白文字=" + StringUtils.isEmpty(" "));
		System.out.println("タブ空白文字=" + StringUtils.isEmpty("\t"));				
	}

}

実行結果
空文字= true
空白文字= true
全角空白文字= true
タブ空白文字= true
空文字= true
空白文字=false
全角空白文字=false
タブ空白文字=false

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?