Java program to find whether the given string is empty or null

Java8Java Programming Object Oriented Programming

The isEmpty() method of the String class returns true if the length of the current string is 0.


import java.util.Scanner;
public class StringEmptyOrNull {
   public static void main(String[] args) {
      System.out.println("Enter a string value ::");
      Scanner sc = new Scanner(;
      String str = sc.nextLine();

      if(str.isEmpty()&& str==null ){
         System.out.println("Given string is empty or null");
         System.out.println("Given string is not empty or null");

Output 1

Enter a string value ::
Hi welcome to tutorialspoint
Given string is not empty or null

Output 2

Enter a string value ::
Given string is empty or null
Updated on 13-Mar-2020 10:38:27