どうも、ちょげ(@chogetarou)です。
文字列(string)が空文字(“”)かどうか判定する方法を紹介します。
方法

文字列(string)が空文字(“”)かどうか判定するには、isEmpty()を使います。
具体的には、「str.isEmpty()
」のように、文字列からisEmpty()を呼び出します。
text.isEmpty()
上記のisEmpty()は、呼び出した文字列が空文字ならば「true」、空文字でなければ「false」を返します。
使用例
public class Main {
public static void main(String[] args) throws Exception {
String text = "Hello,World";
String text2 = "";
System.out.println(text.isEmpty());
System.out.println(text2.isEmpty());
}
}
出力:
false
true
コメント