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 教师闺蜜祝福语简短