This answer is based on your response to the comment(s) asking: "Does your DriverMain
class, override the equals
method?"...
In order to use either an (Array)List, HashTable, HashSet or HashMap, etc. you need to override a "couple" of methods in your DriverMain
class.
For a List, Set, etc.. and some other Collection Types or Map/HashTable to evaluate if your object is a member of its content, you need to provide it with a way to compare the object you are passing to it and the objects it currently holds.
List
The contains(Object o)
method uses the Object's equals(Object o)
method to compare your Object o
to any Object x
(a member of the List Collection).
For more information on this please visit the following link(s): https://docs.oracle.com/javase/tutorial/java/IandI/objectclass.html https://docs.oracle.com/javase/tutorial/collections/interfaces/list.html
Set
The contains(Object o)
method uses the Object's hashCode()
and equals(Object o)
method to compare your Object o
to any Object x
(a member of the Set Collection).
For more information on this please visit the following link(s): https://docs.oracle.com/javase/tutorial/java/IandI/objectclass.html
https://docs.oracle.com/javase/tutorial/collections/interfaces/set.html
Map
The containsKey(Object o)
method uses the Object's hashCode()
and equals(Object o)
method to compare your Object o
to any Object x
(a member of the Map Interface).
For more information on this please visit the following link(s): https://docs.oracle.com/javase/tutorial/java/IandI/objectclass.html
https://docs.oracle.com/javase/tutorial/collections/interfaces/map.html
Important note
There are more ways to approach such a situation, all depending on its implementation. For example: TreeSet
and TreeMap
do not make use of the hashCode()
method.