• Post Reply Bookmark Topic Watch Topic
  • New Topic

Creating a new equals() method  RSS feed

 
Dave Klein
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, I'm having trouble with the comparison of an array of football teams and an array of team names that may or may not be in the football team array. I have read both .txt files into their own arrays and parsed the team array with substring in order to isolate the team name. I know I can read both the search array and the team names individually because I tested it with a println. I think my problem is in the comparison "if" statement.

My output prints the names of each team on their own line and at the end it always says that it can't find each search term.
Ex.
Bears
Bengals
Bills
...
Vikings
Can't find Bills after 32 searches
Bears
Bengals
Bills
...
Vikings
Can't find Eagles after 32 searches
etc

I'm pretty sure I have to create a new equals method but I don't understand how else I'm supposed to compare them other than as I have in the code above. teamArray[j].getName returns a string teamName and search[] is an array of type String so shouldn't each search[s] also be a string? If that is the case(both are strings) how else does one compare two strings besides the built in equals() method?

Any help would be much appreciated.
 
Garrett Rowe
Ranch Hand
Posts: 1296
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you sure there aren't extra spaces appended to the end of the team name which cause the equals() method to return false? Try replacing this debugging line:

System.out.println(teamArray[j].getName());

with this
System.out.println(">" + teamArray[j].getName() + "<");

The addition of the >< characters will let you see the explicitly if there is extra stuff which is fouling your comparison.
[ September 21, 2008: Message edited by: Garrett Rowe ]
 
Dave Klein
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah there is empty space for all but the longest team names. Since I'm using substring() in the Teams constructor to isolate the team name I had to define the String teamName by the ending index of the longest team name. Is there a way to ignore those spaces once I compare, or is this something I have to modify in the Teams constructor?

thanks
 
Dave Klein
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Got it, the trim() method. Thanks for your help Garrett!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!