Java String isEmpty() method with example
Java.lang.String.isEmpty() String method checks whether a String is empty or not. This method returns true if the given string is empty, else it returns false. The isEmpty() method of String class is included in java string since JDK 1.6. In other words, you can say that this method returns true if the length of the string is 0.
Examples:
Input String1 : Hello_Gfg Input String2 : Output for String1 : false Output for String2 : true
Syntax:
public boolean isEmpty() Returns : true if the length of the string is 0.
// Java program to demonstrate working of // isEmpty() method class Gfg { public static void main(String args[]) { // non-empty string String str1 = "Hello_Gfg"; // empty string String str2 = ""; // prints false System.out.println(str1.isEmpty()); // prints true System.out.println(str2.isEmpty()); } } |
chevron_right
filter_none
Output:
false true
Recommended Posts:
- ConcurrentSkipListSet isEmpty() method in Java
- Dictionary isEmpty() Method in Java
- ConcurrentHashMap isEmpty() Method in Java
- Stack isEmpty() method in Java with Example
- Set isEmpty() method in Java with Examples
- ConcurrentLinkedQueue isEmpty() method in Java
- LinkedBlockingDeque isEmpty() method in Java with Example
- LinkedHashSet isEmpty() method in Java
- AbstractSet isEmpty() method in Java with Example
- AbstractSequentialList isEmpty() method in Java with Example
- NavigableMap isEmpty() Method in Java
- HashMap isEmpty() Method in Java
- BitSet isEmpty() method in Java
- NavigableSet isEmpty() method in Java
- HashSet isEmpty() Method in Java
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. 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.



