Table of Contents
String’s isEmpty method checks if length of string is 0 or not. It returns true if length of String is 0 else return false.
When you run above program, you will get below output:
Method Signature:
1 2 3 |
public boolean isEmpty() |
String isEmpty Example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
package org.arpit.java2blog; public class StringIsEmptyExample { /* * @Author : Arpit Mandliya */ public static void main(String[] args) { String str1=""; String str2="java2blog"; String str3=null; System.out.println("str1 isEmpty: "+str1.isEmpty() ); System.out.println("str2 isEmpty: "+str2.isEmpty() ); // str3.isEmpty will throw NullPointerException //System.out.println("str3 isEmpty: "+str3.isEmpty() ); } } |
1 2 3 4 |
str1 isEmpty: true str2 isEmpty: false |
Was this post helpful?
Let us know if this post was helpful. Feedbacks are monitored on daily basis. Please do provide feedback as that\'s the only way to improve.