提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
使用Objects.equals测试是否相等
import java.util.Objects; /* 时代Java公众号 - nowjava.com 提供 */ public class Main { public static void main(String[] args) { // Test for equality boolean isEqual = Objects.equals(null, null); System.out.println("null is equal to null: " + isEqual); isEqual = Objects.equals(null, "XYZ"); System.out.println("null is equal to XYZ: " + isEqual); } }