import
java.util.Arrays;
public
class
ArrayEqualDemo
{
public
static
void
main (String[] args)
{
Student [] arr1 = {
new
Student(
111
,
"bbbb"
,
"london"
),
new
Student(
131
,
"aaaa"
,
"nyc"
),
new
Student(
121
,
"cccc"
,
"jaipur"
)};
Student [] arr2 = {
new
Student(
111
,
"bbbb"
,
"london"
),
new
Student(
131
,
"aaaa"
,
"nyc"
),
new
Student(
121
,
"cccc"
,
"jaipur"
)};
Student [] arr3 = {
new
Student(
111
,
"bbbb"
,
"london"
),
new
Student(
121
,
"dddd"
,
"jaipur"
),
new
Student(
131
,
"aaaa"
,
"nyc"
),
};
System.out.println(
"is arr1 equals to arr2 : "
+
Arrays.equals(arr1, arr2));
System.out.println(
"is arr1 equals to arr3 : "
+
Arrays.equals(arr1, arr3));
}
}
class
Student
{
int
rollno;
String name, address;
public
Student(
int
rollno, String name,
String address)
{
this
.rollno = rollno;
this
.name = name;
this
.address = address;
}
@Override
public
boolean
equals(Object obj) {
Student s = (Student) obj;
return
this
.rollno == s.rollno &&
this
.name.equals(s.name)
&&
this
.address.equals(s.address);
}
}