Java Utils - Objects.deepEquals() Examples

Code Snippets Java Utils Java 


Class:

java.util.Objects

java.lang.Objectjava.lang.Objectjava.util.Objectsjava.util.ObjectsLogicBig

Method:

public static boolean deepEquals(Object a,
                                 Object b)

Returns true if the arguments are deeply equal to each other and false otherwise. Here 'deeply' used in the sense that if a or b are arrays then they are recursively reached for deciding the equality.


Examples


package com.logicbig.example.objects;

import java.util.Objects;

public class DeepEqualsExample {

public static void main(String... args) {
String s1 = "testStr";
String s2 = "testStr";
boolean b = equals(s1, s2);
System.out.println(b);

int[] arr1 = {3, 5, 7};
int[] arr2 = {3, 5, 7};
b = equals(arr1, arr2);
System.out.println(b);


b = equals(null, null);
System.out.println(b);

b = equals(null, arr1);
System.out.println(b);
}

public static boolean equals(Object o1, Object o2) {
return Objects.deepEquals(o1, o2);
}
}

Output

true
true
true
false




See Also