Browse DevX
Sign up for e-mail newsletters from DevX

Tip of the Day
Language: Java
Expertise: Intermediate
Apr 1, 2020

Understandng Objects.deepEquals

We understand how the equals() method works. There is a more elaborate method called deepEquals() that compares in-depth details.

The basic usage is described below. Let's explore more using these as examples.

import java.util.Objects;

public class DeepEquals
   public static void main(String args[])
      DeepEquals deepEquals = new DeepEquals();
   private void proceed()
      System.out.println("Objects.deepEquals(1,1): " + Objects.deepEquals(1,1));
      System.out.println("Objects.deepEquals(1,2): " + Objects.deepEquals(1,2));
      System.out.println("Objects.deepEquals(\"abc\",\"abc\"): " + Objects.deepEquals("abc","abc"));
      System.out.println("Objects.deepEquals(\"aa\",\"ab\"): " + Objects.deepEquals("aa","ab"));


Expected output:

[root@mypc]# java DeepEquals
Getting handle of runtime Console
Got handle of runtime Console
You can now use runtimeConsole object to perform actions of your choice on java.io.Console

M S Sridhar
Thanks for your registration, follow us on our social networks to keep up-to-date