Java程序查找给定的字符串为空还是空
isEmpty()如果当前字符串的长度为0,则String类的方法返回true。
示例
import java.util.Scanner;
public class StringEmptyOrNull {
public static void main(String[] args) {
System.out.println("Enter a string value ::");
Scanner sc = new Scanner(System.in);
String str = sc.nextLine();
if(str.isEmpty()&& str==null ){
System.out.println("Given string is empty or null");
}else{
System.out.println("Given string is not empty or null");
}
}
}输出1
Enter a string value :: Hi welcome to nhooo Given string is not empty or null
输出2
Enter a string value :: Given string is empty or null
热门推荐
10 租房明天搬家祝福语简短
11 求助短信生日祝福语简短
12 新年送老师简短祝福语
13 毕业创意蛋糕祝福语简短
14 新年简短的英文祝福语
15 薛之谦祝福语简短
16 新年祝福语小知识简短
17 中式婚礼贺词祝福语简短
18 给新年祝福语简短独特