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?
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:
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 ]
Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peter
posted 10 years ago
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?
posted 10 years ago
Got it, the trim() method. Thanks for your help Garrett!
My pie came with a little toothpic holding up this tiny ad:
how do I do my own kindle-like thing - without amazon