Given a string str, the task is to check if this string is empty or not, in Java.
Input: str = "" Output: True Input: str = "GFG" Output: False
- Get the String to be checked in str
- We can simply check if the string is empty or not using the isEmpty() method of String class
- Print true if the above condition is true. Else print false.
Below is the implementation of the above approach:
Is string "GeeksforGeeks" empty? false Is string "" empty? true
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.