Compaing objects in two arrays. Would Really appreciate your help experts

i have a program that reads data from a text file, i have one string in the file that needs to be read as seperate chars e.g fota as they both stand for something. here is how i did this.

if(line.equals("m")){

name = reader.readLine();

surname = reader.readLine();

enjoytime = reader.readLine();

char[] menjoytime = enjoytime.toCharArray();

System.out.println(menjoytime1);

hatetime= reader.readLine();

Male male =new Male(name, surname, enjoytime, hatetime);

listMale.add(male);

now i need to compare the elements in the array for each that element that matches a females objects i need to apply the below ideas, but i can't do this without knowing how to compare the objects within in the array to see how many match is this possible and if so how?

an example would be one array contaning fota and another tca should equal 2 elements that match thus i should be able to create some code that will match my idea below.

* for each char in enjoytime that matches +2 compatbility point,

* for each char in hate that matches +1 compatbility point

* for each char in enjoytime that matcher in hatetime -2 compatbility points

* then match the two with that have a similar or same number.

* interat through male and female arraylist to find best match.

* then print the two couples to screen.

[1548 byte] By [aaron1uka] at [2007-11-26 12:22:04]
# 1

You dont need to convert them to arrays. You can loop through a String.

int count = 0;

for(int i=0; i<enjoytime.length(); i++)

{

char c = enjoytime.charAt(i);

//increment count if this char is the same as the female's

}

>

CaptainMorgan08a at 2007-7-7 15:14:45 > top of Java-index,Archived Forums,Socket Programming...
# 2

using this method i would have to give a different name for the enjoytime field in both classes (male & female) as i would have a problem comparing the chars in each string of each of the classes correct here is the text file i am using to test if my methods work;

m //sex

Evans //surname

Aaron //forname

fota //likes

cl //dislikes

f //sex

Thomas //surname

Ceri //forname

tca //likes

fo //dislikes

I hope that helps and i really do appreciate your help.

Message was edited by:

aaron1uk

aaron1uka at 2007-7-7 15:14:45 > top of Java-index,Archived Forums,Socket Programming...
# 3
so anyone have an awnser?
aaron1uka at 2007-7-7 15:14:45 > top of Java-index,Archived Forums,Socket Programming...
# 4
You'll have to explain a bit more clearly what was wrong with CaptainMorgan's answer as it seems to do exactly what you want.
passgodeva at 2007-7-7 15:14:45 > top of Java-index,Archived Forums,Socket Programming...
# 5

i have two arraylists of males and females, they both have a field enjoytime. i need to compare the chars in this field. but not with just one male and one female i need to do it with everyone i thought i would go through each male in the arraylist and compare every female and i some how need to match one male with one female. (it's a dating agency). and to be honest i'm not sure how i could do this. i suppose after i have found one best match i need to remove them from the arraylist and add them to a new "couples" arraylist.

agh this is getting confusing.

aaron1uka at 2007-7-7 15:14:45 > top of Java-index,Archived Forums,Socket Programming...
# 6
Look at java.lang.Comparable and java.util.Comparator. These might give you an idea.
filestreama at 2007-7-7 15:14:45 > top of Java-index,Archived Forums,Socket Programming...