Results 1 to 3 of 3

Thread: comparing vectors in java

  1. #1
    Join Date
    Jun 2007

    Question comparing vectors in java


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

  2. #2
    Join Date
    Dec 2002
    Calgary, Canada
    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


    Message Posting Guidelines In These Forums, Please read these before posting any question.
    Web site: webapplikations.com
    Web Resources Page:Web Resources

  3. #3
    Join Date
    Jul 2007
    You can probably use Commons-Collections to do that.
    Look at CollectionUtils.retainAll().


    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.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center

Recent Articles