如何測試String是否為null或空?
我們可以使用字串類的isEmpty()方法驗證給定的字串是否為空。此方法僅在長度()為 0 時返回 true。
示例
import java.lang.*;
public class StringDemo {
public static void main(String[] args) {
String str = "tutorialspoint";
// prints length of string
System.out.println("length of string = " + str.length());
// checks if the string is empty or not
System.out.println("is this string empty? = " + str.isEmpty());
}
}輸出
length of string = 14 is this string empty? = false
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP