Java null String equals result

后端 未结 8 740
星月不相逢
星月不相逢 2020-12-16 15:11

Please help me how does the string.equals in java work with null value? Is there some problem with exceptions? Three cases:

boolean result1,result2, result3;         


        
8条回答
  •  我在风中等你
    2020-12-16 15:31

    Use Objects.equals() to compare strings, or any other objects if you're using JDK 7 or later. It will handle nulls without throwing exceptions. See more here: how-do-i-compare-strings-in-java

提交回复
热议问题