/    Sign up×
Community /Pin to ProfileBookmark

comparing vectors in java

hi,

iam having vector v1 and v2 of diff size,i need compare v1 and v2 and find unique records from them
pls help
arvin

to post a comment
Java

2 Comments(s)

Copy linkTweet thisAlerts:
@Khalid_AliJun 23.2007 — you will have to write your own comparison routine to do that, I don't think there is in java that will automatically tell you that.

there are few things that come to mind,

1. first see if both vectors are of the same size.

2. then scan through both and compare each item at the same index.

3. You will have to know in advance that what is the type of each item in the vector so that you can compare correctly..

just my 0.001 cent
Copy linkTweet thisAlerts:
@cst97025Jul 01.2007 — You can probably use Commons-Collections to do that.

Look at CollectionUtils.retainAll().

http://jakarta.apache.org/commons/collections/api-release/org/apache/commons/collections/CollectionUtils.html#retainAll(java.util.Collection,%20java.util.Collection)

This assumes that your Vectors contain all the same type of object. If it's your own object, you should probably make sure you code its equals() method.

At least I'm pretty sure it will work with Vectors...

If not, maybe you can switch them to ArrayLists.
×

Success!

Help @arvin84 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.19,
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,
)...