Open In App
Related Articles

How to Check String is Empty or Not in Dart (Null Safety)?

Improve Article
Improve
Save Article
Save
Like Article
Like

We can check a string is empty or not by the String Property isEmpty. If the string is empty then it returns True if the string is not empty then it returns False.

Syntax: String.isEmpty 

Return : True or False.

Example 1:

Dart




// main function start
void main() {
   
    // initialise a string st
    String? st = "";
   
    // print string is empty or not
    print(st.isEmpty);
}


Output:

true

Example 2:

Dart




// main function start
void main() {
   
    // initialise a string st
    String? st = "Geeksforgeeks";
   
    // print string is empty or not
    print(st.isEmpty);
}


 Output:

false
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Last Updated : 09 Aug, 2021
Like Article
Save Article
Previous
Next
Similar Reads