You could do something like this
add a getter method for name in your Gene class
public String getName() {
return name;
}
then in another class use logic similar to this
ArrayList<Gene> matchingGenes = new ArrayList<>();
for (Gene gene1 : genelist1) {
for (Gene gene2 : genelist2) {
if gene1.getName().equals(gene2.getName) {
matchingGenes.add(gene1);
matchingGenes.add(gene2);
}
}
}
This will leave you with a list containing pairs of every Gene that shared a name with a Gene from the other list.
solved How to determine equality of gene objects by gene name in Java