- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Check if a String is not empty ("") and not null in Java
Let’s say we have the following string −
String myStr1 = "Jack Sparrow";
Let us check the string now whether it is not null or not empty.
if(myStr != null || myStr.length() != 0) { System.out.println("String is not null or not empty");
Example
public class Demo { public static void main(String[] args) { String myStr = "Jack Sparrow"; boolean res; if(myStr != null || myStr.length() != 0) { System.out.println("String is not null or not empty"); } else { System.out.println("String is null or empty"); } } }
Output
String is not null or not empty
- Related Articles
- Java Program to check if a string is empty or not
- Check if a String is empty ("") or null in Java
- Check if a directory is not empty in Java
- Check if a String is whitespace, empty ("") or null in Java
- Java Program to Check if a String is Empty or Null
- Empty string in not-null column in MySQL?
- Check if a list is not empty in MongoDB?
- Python program to check if the string is empty or not
- Golang program to check if a string is empty or null
- How to Check if an Array is Empty or Not in Java
- Check whether a Stack is empty or not in Java
- Check whether a HashSet is empty or not in Java
- Check whether a NavigableMap empty or not in Java
- How can we check if a JSON object is empty or not in Java?\n
- Check whether IdentityHashMap empty or not in Java?

Advertisements