Java – s.equals (“”) and “” What’s the difference between equals (s)

First: s.equals ("") and "" What's the difference between equals (s)?

Second: what if I want to perform one of these functions? “”. Substring (1) or '' charAt(0)

Solution

With regard to equality, there is no difference between the two equal variants when it comes to results But the second is nullsafe If s is null, the first will throw a NullPointerException, and the second variable will only evaluate to false

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
分享
二维码
< <上一篇
下一篇>>