Java – check whether the condition is’ null ‘
•
Java
I have questions about checking null conditions For example:
if(some conditon) value1= value; //value1 is string type else value1= "";
Similarly, the other four string values have similar conditions What I need is that I want to check whether all five string values are null in order to do some other specific parts I did
if(value1 == null) { }
However, the PGM control did not enter the loop, although value1 = "" Then I tried
if(value1 ==""){ }
It's no use
We can't check whether null and '' values are the same? Who can help me??
Solution
If you want to check whether the string is null, use
if (s == null)
If you want to check whether the string is empty, use
if (s.equals(""))
or
if (s.length() == 0)
or
if (s.isEmpty())
An empty string is an empty string It's not empty And = = must not be used to compare string contents== Test whether two variables refer to the same object instance If they contain the same characters, they will not
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码