Writing code today finds a question about whether a string is empty
Stick to My Code:
if (!username.equals ("") &&!userpassword.isempty () &&! Phstring.isempty ()&&!userpassword2.isempty ())
As above: If there is nothing in this string here phstring, then Phstring.isempty () This method to determine whether NULL will report null pointer exception
When phstring= "51cto", the return value of Phstring.isempty () is false;
This means that the return value of this method is Boolean , and if Length () is 0 returns True, False otherwise.
But this method of compatibility is not good, also easy to make mistakes the following are some common methods of judging null:
method One: Most people use a method, intuitive, convenient, but inefficient.
method Two: Compare string length, high efficiency, is the best I know of a method.
method Three: Java SE 6.0 only begins to provide methods that are nearly equal in efficiency and method two, but for compatibility reasons it is recommended to use method two.
1:if (s = = NULL | | s.equals (""));
2:if (s = = NULL | | s.length () <= 0);
3:if (s = = NULL | | s.isempty ());
Reference from: http://blog.csdn.net/fengxuezhiye/article/details/7763384
This article is from the "10055957" blog, please be sure to keep this source http://10065957.blog.51cto.com/10055957/1702984
Java method Summary for determining whether a string is empty