4

Java 11 检查字符串是否为空或只有空格

 2 years ago
source link: https://www.jdon.com/62498
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Java 11 检查字符串是否为空或只有空格

isBlank() 方法检查字符串是否为空或只有空格。

如果字符串为空或仅包含空白代码点,isBlank() 方法返回 true 否则返回false。 String API 有另一个方法isEmpty()也检查字符串是否为空。

String input = "java-jdon";
boolean isBlank = input.isBlank();
System.out.println(isBlank);
String input2 = "";
isBlank = input2.isBlank();
System.out.println(isBlank);
String input3 = "   ";
isBlank = input3.isBlank();
System.out.println(isBlank);

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK