String str1 = "Hello"; String str2 = "Hello"; Boolean result = Objects.equals(str1, str2); System.out.println(result); // Output: true
class Person { int id; String name; public Person(int id, String name) { this.id = id; this.name = name; } } Person p1 = new Person(1, "John"); Person p2 = new Person(2, "Mary"); Boolean result = Objects.equals(p1, p2); System.out.println(result); // Output: falseIn this example, we are comparing two `Person` objects using the `equals` method provided by the `Objects` class. Since the contents of the objects are not identical, the result is false. Package Library: `java.util.Objects`