Program to check if the String is Null in Java
Given a string str, the task is to check if this string is null or not, in Java.
Input: str = null Output: True Input: str = "GFG" Output: False
- Get the String to be checked in str
- We can simply compare the string with Null using == relational operator.
if(str == null)
- Print true if the above condition is true. Else print false.
Below is the implementation of the above approach:
Is string [GeeksforGeeks] null? false Is string [null] null? true
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.