Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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
Advertisements