This is a code I found on geeks for geeks I am confused about class Object and what is deep comparison I am quite new to Java and I am trying to get to know as much thing in depth as I can. Please don't get irritated by my silly doubts
import java.util.Arrays;
class Test
{
public static void main (String[] args)
{
// inarr1 and inarr2 have same values
int inarr1[] = {1, 2, 3};
int inarr2[] = {1, 2, 3};
Object[] arr1 = {inarr1}; // arr1 contains only one element
Object[] arr2 = {inarr2}; // arr2 also contains only one element
if (Arrays.equals(arr1, arr2))
System.out.println("Same");
else
System.out.println("Not same");
}
}
Compare the results if you add a Arrays.deepEquals comparison
In the second case it should be "Same". This is because while the Object[]'s and int[]'s themselves are different objects, their int contents are the same