Q:

How to check whether a given string is empty or not in Java?

belongs to collection: Java String Programs

0

How to check whether a given string is empty or not in Java?

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Consider the program:

Given string (Input string) and we have to whether it is empty string or not?

/*Java Program to check whether string is empty or not*/

public class JavaisEmptyPrg
{
	public static void main(String args[])
	{
		String str1="www.includehelp.com";
		String str2="";

		if(str1.isEmpty()==true)
		System.out.println("Str1 is an empty string.");
		else
		System.out.println("Str1 is not an empty string.");

		if(str2.isEmpty()==true)
			System.out.println("Str2 is an empty string.");
		else
			System.out.println("Str2 is not an empty string.");
	}
}

Output

Complie: javac JavaisEmptyPrg.java
Run: java JavaisEmptyPrg

Output

Str1 is not an empty string.
Str2 is an empty string.

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Java String Programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Java program to convert string to lowercase and up... >>
<< How to reverse a string in Java with and without u...