Objects.equals checks both references for null before delegating to equals, so it never throws a NullPointerException the way a.equals(b) would when a happens to be null.
String a = null;
String b = "value";
System.out.println("null vs value: " + Objects.equals(a, b));
System.out.println("null vs null: " + Objects.equals(null, null));
System.out.println("value vs value: " + Objects.equals("value", "value"));
null vs value: false
null vs null: true
value vs value: true
Run this yourself in the Online Java Compiler, spin up a live REST API in the API Sandbox, or practise with Java interview questions.
Published 2026-09-27