I saw the following program on the internet
public class Test1{
public static void main(String[] args)
{
Integer int1 = new Integer(10);
Vector vec1 = new Vector();
LinkedList list = new LinkedList();
vec1.add(int1);
list.add(int1);
if(vec1.equals(list)) System.out.println("equal");
else System.out.println("not equal");
}
}
The answer it print is “equal”.
How it is possible?
Thanks
Dilip
Because both a LinkedList and Vector implement List#equals()
Specifically, here is the exact reason for this behavior.
This definition ensures that the equals method works properly across different implementations of the List interface.