Correct way to check for null or empty or string containing only spaces is like this:
if(str != null && !str.trim().isEmpty()) { /* do your stuffs here */ }
More Related Contents:
- JAVA- JFrame- non static method cannot be referenced from a static context [duplicate]
- why setXXX() method is not overrinding?
- Using threads to make database requests
- Java – get pixel array from image
- Hibernate: different object with the same identifier value was already associated with the session [duplicate]
- How to represent double values as circles in a 2d matrix in java
- Hibernate, @SequenceGenerator and allocationSize
- How to call the overridden method of a superclass?
- Eclipse Autocomplete (percent sign, in Juno)
- How to add a new line of text to an existing file in Java? [duplicate]
- Why only 1 public class in Java file
- Static versus non-static lock object in synchronized block
- Encrypt and decrypt with AES and Base64 encoding
- Java – removing first character of a string
- Android Firestore convert array of document references to List
- Eclipse reading stdin (System.in) from a file
- Create simple POJO classes (bytecode) at runtime (dynamically)
- “Defective token detected” error (NTLM not Kerberos) with Kerberos/Spring Security/IE/Active Directory
- indexOf Case Sensitive?
- Android Studio: failed to complete gradle execution, cause is empty
- What are the time complexities of various data structures?
- Caused by: java.security.UnrecoverableKeyException: Cannot recover key
- Is it faster to add to a collection then sort it, or add to a sorted collection?
- Java still uses system memory after deallocation of objects and garbage collection
- How to use HTML and CSS as a Java application GUI?
- Regex for checking if a string is strictly alphanumeric
- How to use Collections.sort() in Java?
- org.openqa.selenium.ElementClickInterceptedException: element click intercepted error using Selenium and Java in headless mode
- Is it possible to merge iterators in Java?
- Is it possible to get the object reference count?