Tutorial Gateway

  • C
  • C#
  • Java
  • Python
  • SQL
  • MySQL
  • Js
  • BI Tools
    • Informatica
    • Talend
    • Tableau
    • Power BI
    • SSIS
    • SSRS
    • SSAS
    • MDX
    • R Tutorial
    • Alteryx
    • QlikView
  • More
    • C Programs
    • C++ Programs
    • Go Programs
    • Python Programs
    • Java Programs

Java String isEmpty Method

by suresh

The Java String.isEmpty method is one of the Java String Methods, which is to check whether the user-specified string is Empty or Not. If the length of the user-specified string is zero, then the String.isEmpty will return TRUE.

In this article, we will show how to find the Empty strings using a Java string isEmpty method with an example. The basic syntax of the String isEmpty in Java Programming language is as shown below.

public Boolean isEmpty() // It will return Boolean True or False as Output

//In order to use in program
String_Object.isEmpty()
  • String_Object: Please specify the valid String Object.

Java String isEmpty Method example

The String.isEmpty method returns True if and only if the length of the user-specified string is Zero. Otherwise, it will return False. In this Java program, We are going to find the same.

//Java String.isEmpty Method example
package StringFunctions;
public class StringIsEmpty {

	public static void main(String[] args) {
		String str = "Tutorial GateWay";
		String str1 ="";
		String str2 =" ";
		
		System.out.println("The Length of a String Str = " + str.length());
		System.out.println("Is this String Str is Empty or Not? = " + str.isEmpty());
		
		System.out.println("\nThe Length of a String Str1 = " + str1.length());
		System.out.println("Is this String Str1 is Empty or Not? = " + str1.isEmpty());
		
		System.out.println("\nThe Length of a String Str2 = " + str2.length());
		System.out.println("Is this String Str2 is Empty or Not? = " + str2.isEmpty());
	}
}
Java String isEmpty Method 1

From the following statements, the first Java statement will find the length of the above-specified string (which is 16). The second statement will call the public Boolean isEmpty () method to check whether the above-specified string is empty or not. As we all know, length = 16 (which is not equal to zero), so the output of Java String isEmpty will be False.

System.out.println("The Length of a String Str = " + str.length());
System.out.println("Is this String Str is Empty or Not? = " + str.isEmpty());

Here we declared the String variable and assigned an empty string using the following statement

String str1 ="";

From the following System.out.println statement will call the public Boolean isEmpty () method to check whether the above-specified string is empty or not. As we all know, length = 0 so the output will be True

System.out.println("Is this String Str1 is Empty or Not? = " + str1.isEmpty());

Next, we declared the String variable and assigned Empty space as a value using the following statement.

String str1 =" ";

From the above screenshot, you can observe that the String function is returning False. It is because the length of the above-specified string is 1. So Java isEmpty() method is returning False.

System.out.println("Is this String Str2 is Empty or Not? = " + str2.isEmpty());

Placed Under: Java

  • SQL DML, DDL, DCL & TCL Cmds
  • SQL NOT EXISTS Operator
  • SQL UPDATE from SELECT
  • SQL AFTER UPDATE Triggers
  • SQL Get Column Names in Table
  • SQL IF ELSE
  • SQL ACID Properties
  • SQL FOR XML PATH
  • Java Two Dimensional Array
  • Java Perfect Number Program
  • Java Count Digits in a Number
  • C Compare Two Strings Program
  • C Print Prime Numbers 1 to 100
  • C program to Reverse a String
  • C Palindrome Number Program
  • C Program for Palindrome String
  • C Remove Duplicate String Chars
  • C Square of a Number Program
  • C Sum and Average of N Number
  • Python Fibonacci Series program
  • Python Area Of Circle Program
  • Python Prime Numbers 1 to 100
  • Python Program for Leap Year
  • Tableau Rank Calculation
  • Tableau Google Maps usage
  • Power BI Format Dates
  • Power BI Top 10 Filters
  • Power BI – Create Hierarchy
  • Power BI DAX Math Functions
  • Learn SSIS in 28 Days
  • SSIS Transformations
  • SSIS Incremental Load
  • SSRS Drill Through Reports
  • SSRS Drill Down Reports
  • R Programming Tutorial

Copyright © 2021 · All Rights Reserved by Suresh

About Us | Contact Us | Privacy Policy