Any difference between String = null and String.isEmpty?
java, null, string
Solution
The empty string is a string with zero length. The null value is not having a string at all.
- The expression `s == null` will return `false` if s is an empty string.
- The second version will throw a `NullPointerException` if the string is null.
Here's a table showing the differences:
+-------+-----------+----------------------+
| s | s == null | s.isEmpty() |
+-------+-----------+----------------------+
| null | true | NullPointerException |
| "" | false | true |
| "foo" | false | false |
+-------+-----------+----------------------+
Problem
Is there any difference when using a if-statement to check if the string is empty by using String = null or String.isEmpty() ? ie: ``` public String name; if(name == null) { //do something } ``` or ``` public String name; if(name.isEmpty()) { //do something } ``` if there is any different (including performance issues) please let me know.