I think you have much bigger problems than that. Classes Male, Female, Single? Those are attributes of a Person class, not classes in and of themselves. Your design needs rework.
You need Person and Couple classes. You also need a model that reflects the real world. Like it or not, you can have Male-Male and Female-Female couples.
I'd write it like this. As you can see, List works perfectly:
Gender.java:
public enum Gender
{
MALE, FEMALE;
}
MaritalStatus.java:
public enum MaritalStatus
{
SINGLE, MARRIED, DIVORCED, WIDOWED, SEPARATED;
}
Person.java:
import java.text.DateFormat;
import java.util.Date;
public class Person
{
private String name;
private Date birthdate;
private Gender gender;
private MaritalStatus maritalStatus;
public Person(String name)
{
this(name, new Date(), Gender.MALE, MaritalStatus.SINGLE);
}
public Person(String name, Gender gender)
{
this(name, new Date(), gender, MaritalStatus.SINGLE);
}
public Person(String name, Date birthdate)
{
this(name, birthdate, Gender.MALE, MaritalStatus.SINGLE);
}
public Person(String name, Date birthdate, Gender gender)
{
this(name, birthdate, gender, MaritalStatus.SINGLE);
}
public Person(String name, Date birthdate, Gender gender, MaritalStatus maritalStatus)
{
if ((name == null) || (name.trim().length() == 0))
throw new IllegalArgumentException("name cannot be blank or null");
this.name = name;
this.birthdate = ((birthdate == null) ? new Date() : new Date(birthdate.getTime()));
this.gender = gender;
this.maritalStatus = maritalStatus;
}
public String getName()
{
return name;
}
public Date getBirthdate()
{
return new Date(birthdate.getTime());
}
public Gender getGender()
{
return gender;
}
public MaritalStatus getMaritalStatus()
{
return maritalStatus;
}
@Override
public boolean equals(Object o)
{
if (this == o)
{
return true;
}
if (o == null || getClass() != o.getClass())
{
return false;
}
Person person = (Person) o;
if (!birthdate.equals(person.birthdate))
{
return false;
}
if (gender != person.gender)
{
return false;
}
if (maritalStatus != person.maritalStatus)
{
return false;
}
if (!name.equals(person.name))
{
return false;
}
return true;
}
@Override
public int hashCode()
{
int result = name.hashCode();
result = 31 * result + birthdate.hashCode();
result = 31 * result + gender.hashCode();
result = 31 * result + maritalStatus.hashCode();
return result;
}
@Override
public String toString()
{
return "Person{" +
"name='" + name + '\'' +
", birthdate=" + DateFormat.getDateInstance(DateFormat.MEDIUM).format(birthdate) +
", gender=" + gender +
", maritalStatus=" + maritalStatus +
'}';
}
}
Couple.java:
public class Couple
{
private Person ying;
private Person yang;
public Couple(Person ying, Person yang)
{
this.ying = ying;
this.yang = yang;
}
public Person getYing()
{
return ying;
}
public Person getYang()
{
return yang;
}
@Override
public String toString()
{
return "Couple{" +
"ying=" + ying +
", yang=" + yang +
'}';
}
}
Dating.java:
import java.util.ArrayList;
import java.util.List;
public class Dating
{
private List<Person> individuals = new ArrayList<Person>();
private List<Couple> couples = new ArrayList<Couple>();
public static void main(String[] args)
{
Dating dating = new Dating();
dating.addIndividual(new Person("Jack"));
dating.addIndividual(new Person("Mike"));
dating.addIndividual(new Person("Lydia", Gender.FEMALE));
dating.addIndividual(new Person("Kate", Gender.FEMALE));
System.out.println(dating);
}
public void addIndividual(Person p)
{
this.individuals.add(p);
}
public void removeIndividual(Person p)
{
this.individuals.remove(p);
}
public Person findIndividual(String name)
{
Person found = null;
if (name != null)
{
for (Person p : this.individuals)
{
if (name.equals(p.getName()))
{
found = p;
break;
}
}
}
return found;
}
@Override
public String toString()
{
return "Dating{" +
"individuals=" + individuals +
", couples=" + couples +
'}';
}
}