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
- Program to check if the String is Empty in Java
- Program to check if a String in Java contains only whitespaces
- Java program to check whether a string is a Palindrome
- Interesting facts about null in Java
- Null Pointer Exception In Java
- Calling a method using null in Java
- Replace null values with default value in Java Map
- Method overloading and null error in Java
- C Program to Check if a Given String is Palindrome
- Program to check if first and the last characters of string are equal
- Python program to check if a string is palindrome or not
- Program to check if input is an integer or a string
- Python program to check if given string is pangram
- Python program to check if a string contains all unique characters
- Python program to check if given string is vowel Palindrome
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.