Java – Check if a String is empty or null
In Java, we can use (str != null && !str.isEmpty()) to make sure the String is not empty or null. StringNotEmpty.java package com.mkyong; public class StringNotEmpty { public static void main(String[] args) { System.out.println(notEmpty("")); // false System.out.println(notEmpty(null)); // false System.out.println(notEmpty("hello")); // true System.out.println(notEmpty(" ")); // true, a space… } private static boolean notEmpty(String str) { …