Find Blank and Empty String

Java-Find Blank and Empty String

Find Blank and Empty String

The String class provides two methods, isBlank() and isEmpty(), that used to find if the string is empty or blank. The isBlank() method returns true if the string is empty or contains only white space codepoints, otherwise false. The isEmpty() method returns true if, and only if, length() is 0. For examples:


Find Blank and Empty String


Program

Find Blank and Empty String

Program Source

public class Javaapp {

    public static void main(String[] args) {

        String str1 = "\u0000\u0007\u001B\u0011";
        String str2 = "\u004A\u0041\u0056\u0041";
        String str3 = "\u0020\u0020\u0020\u0020";
        String str4 = "    ";
        String str5 = "";
        System.out.println("str1.isBlank()-> "+str1.isBlank());
        System.out.println("str1.isEmpty()-> "+str1.isEmpty());
        System.out.println("str2.isBlank()-> "+str2.isBlank());
        System.out.println("str2.isEmpty()-> "+str2.isEmpty());
        System.out.println("str3.isBlank()-> "+str3.isBlank());
        System.out.println("str3.isEmpty()-> "+str3.isEmpty());
        System.out.println("str4.isBlank()-> "+str4.isBlank());
        System.out.println("str4.isEmpty()-> "+str4.isEmpty());
        System.out.println("str5.isBlank()-> "+str5.isBlank());
        System.out.println("str5.isEmpty()-> "+str5.isEmpty());
    }
}

Leave a Comment