如何測試字串是否為空或空字串?
我們可以使用 String 類的 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
廣告
資料結構
網路
關係型資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP