/    Sign up×
Community /Pin to ProfileBookmark

Hi ive a question about vectors. I have two vectors each containing the same string of 8 words:
ONE TWO THREE THERE
FOUR FIVE SIX SEVEN
and i am comparing the two:

int sameWord = 0;
for(int i = 0; i < vector1.size(); i++)
{
Object a = vector1.elementAt(i);

for(int j = 0; j < vector2.size(); j++)
{
Object b = vector2.elementAt(j);
if(a.toString().compareTo(b.toString()) == 0){
sameWord++;

}
}
}

the result however when comparing the two is that 9 of these words are the same whereas i would expect it to be eight since there are only 8 words in each string and both vectors contain the same string. Does anybody know why this result would be 9?
Thanks

to post a comment
Java

5 Comments(s)

Copy linkTweet thisAlerts:
@OakNov 14.2005 — The result is actually 8 as you will see when running the attached file.

I am not sure how you were getting 9 but it makes no sense. Do you have a screen shot that proves you were getting 9?

[upl-file uuid=19773028-c3b3-4abb-8c9f-1f02d19488f2 size=577B]Vectors.zip[/upl-file]
Copy linkTweet thisAlerts:
@Khalid_AliNov 14.2005 —  Object b = vector2.elementAt(j);

if(a.toString().compareTo(b.toString()) == 0){

[color=red]sameWord++;[/color]

...... i would expect it to be eight since there are only 8 words in each string and both vectors contain the same string. Does anybody know why this result would be 9?

Thanks[/QUOTE]


could it be that you have initialized sameWord=1 in the beginning somewhere?
Copy linkTweet thisAlerts:
@OakNov 14.2005 — I doubt it since he probably used copy and paste to add the code to the post.
Copy linkTweet thisAlerts:
@Khalid_AliNov 14.2005 — if u are right then he certainly has more values int he vector then he expects
Copy linkTweet thisAlerts:
@OakNov 15.2005 — Yeah, from the code he/she posted that is that only thing we can assume. I have a feeling he/she has already figured it out ?
×

Success!

Help @Rabbit3cat spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...