Merging two vectors

Hi, I have two vectors, each containing different information with the exception of the names, which are the same in both vectors. I want to combine vector 1 information with vector 2 information for each name.
Is this possible?
example: vector 1 contains several attributes for each of many fruits.
vector 2 contains different attributes for the same fruits.
How can I get all the attributes for each fruit in one vector?

I take it the names are unique?
1. You iterate through the first vector. For each name you iterate through the second vector. When you find the same name you have the two objects and can show the combined information.
2. The above algoritm is quadratic and slow for large vectors. It's possible to make it linear by temporarily storing the second vector in a HashMap.
3. You sort both vectors on name. Then you iterate through them in "parallell". This is also a linear algoritm (apart from the initial sorts).
PS. It's better to use ArrayList, the modern version of Vector.

Similar Messages

  • Merging two sorted Vectors into one

    I wish to write a function that will accept two Vectors which are sorted and merge them into a single sorted Vector. I plan to use the compareTo() function to perform the comparisons between objects. I want the function to do this task for Vectors containing Integer, String, or any User Defined Classs (both the vectors will be containing objects of same class though).
    However, I am unable to do this because whether I use an iterator or write a loop to acces the elements of the Vector, I am required to typecast the returned object. I am using J2SE 1.4.2
    1 Vector mergeSortedVectors(Vector a, Vector b) {
    2         Vector c = new Vector();
    3         int p1=0, p2=0;
    4         while(p1<a.size() && p2<b.size()) {
    5                int result = ((Object)a.get(p1++)).compareTo((Object)b.get(p2++));
    6                // insertion logic
    7         }
    8 }Line no 5 gives me a compile error: Object.compareTo() not found
    Please help

    Cast it to Comparable instead of Object.

  • Please help me to merge two places.sqlite to get my old and New history at the same time, every time i rename my two places.sqlite to see my old and new history

    every time i rename my new places.sqlite to see my old history and come back rename old places.sqlite to see my new history, i tired and i found No Way to merge two places.sqlite :( but it's must be found this way for The PPL to see their old and new history :(
    Thank You all in Advance

    You can't merge history otherwise then using Sync to store the history and bookmarks of one places.sqlite on the Sync server and then disconnect.<br />
    Copy the second places.sqlite file to your Firefox profile folder with Firefox closed.
    Then setup Sync once again using that account and merge the content on the Sync server with your computer.
    * Merge this device's data with my Sync data

  • TS3988 how do i merge two icloud accounts - on on my computer and ipad, a different icloud id on my iphone?

    How do I merge two iCloud accounts into one?  One account is on my mac and ipad, the other on my iphone.

    Welcome to the Apple community.
    You cannot merge accounts, you will need to choose one and use it.

  • How do I merge two valid, purchased iTunes accounts into one so all my music is in same account?

    I have two valid, purchasd iTunes accounts.  Older iPod has some great music, I just got a new iPad and set up second iTunes account, bought some more iTunes items for that account.  Just discovered iCloud.  Now I want to put all my music from both accounts onto the cloud so I can access it on all my apple devices.   Can't seem to add from one account to the other.  Can sign onto the new account wiht my old iPod, but it will not let me sync without erasing all the music on the device.  How can I merge these two accounts into one?
    PS  Makes you wonder how helpful support is when the usernames "Frustrated," "really frustrated," and "Help!!!!" are all taken...lol

    HeyStupid wrote:
    how do I merge two valid, purchased iTunes accounts into one so all my music is in same account?
    You cannot. iTunes pruchases remian tied to the account they were purchased with.
    I just got a new iPad and set up second iTunes account,
    Why?
    Remove your info from new account, update old account as needed and use that.

  • How can I merge two iPhoto libraries stored on an external drive?

    Today I was in a One-to-One at the Apple Store.  I want to merge two i-Photo libraries into one.  One library is on my Air, the other is on my iMac.  Both libraries have been moved to an external drive.  When I try to move one onto the other, they won't go.  Yet I am certain that while at the store today, the person there started to merge them.  He did not need the library manager software in order to do so.  We stopped the merge in order to move on to another issue.  Now that I am home, I can't get the libraries to merge.  What am I failing to do?  Thanks!

    The only way to merge two libraryies is to use  iPhoto Library Manager which will merge two libraries and keep keywords, titles, faces, places, and other metadata intact.
    If one imports one library into another library every image file in the first library, originals, thumbnails, face files, etc,  get imported as an original photo. You will end up with a total mess.  DO NOT IMPORT ONE LIBRARY INTO ANOTHER LIBRARY!
    If you have backup copies of your libraries get them back and use iPhoto Library Manager to merge them.
    OT

  • Can you merge two user accounts on macbook? my wife has created a user on her new macbook , then inadvertently created a second one when using the migration tool. 1st ac has her office 365 install, yet 2nd has her itunes database, docs and contacts.

    Can you merge two user accounts on a macbook? my wife has created a new user on her new macbook air then, inadvertently, created a second one when using the migration tool. 1st a/c has her office 365 install, while 2nd has her itunes database, docs and contacts. What is the best way forward to get everything into the one account? Not sure if the office 365 will allow another installation into the second account, otherwise would just do that and delete the first, if that is possible?

    There is no merge but you can move data from one account to another via the Shared folder. Data is copied from Shared. Watch your free space when copying. These are large files.  Do one at a time if you are on a small drive. After making copy, delete from other users before you start next copy.
    Office365 installs in the main Applications folder and is available for all users on the computer. Activation is tied to the drive not the User.

  • How do I merge two different libraries, linked to one account? They're on two different computers but I want them to be on one

    How do I merge two different libraries, linked to one account? They're on two different computers but I want them to be on one

    This should do the trick
    Home Sharing Learn More
    http://support.apple.com/kb/HT201976
    Best of Luck

  • HT204053 Can you merge two Apple IDs into one?  It was a common issue caused by the iPhone 4 and has been corrected, but transferring purchases in iTunes is a pain with two IDs.

    For a brief time when iPhone 4, iOS 4 came out, many of us ended up with two Apple IDs.  I want to know if anyone can please provide me with simple step-by-step instructions on merging two Apple IDs into one?  It would make transferring purchases on iTunes much easier and reliable.  I realize i desperately need an iOS update, but i had no laptop for over two years!  I'm posting a cry for help on that in another community.  Thank you all.

    No,
    Apple IDs cannot be merged. You should use your preferred Apple ID from now on, but you can still access your purchased items such as music, movies, or software using your other Apple IDs.

  • Can i merge two apple ids into one

    i have two apple IDs that i need to merge.  money is both accouts, paid apps on both accounts.
    What are my options?
    thanks

    http://appletoolbox.com/2012/10/can-i-merge-two-or-more-apple-ids-using-multiple -apple-ids/
     Cheers, Tom

  • Can you merge two apple ids

    I have two Apple id's. Not sure why. but one is for my iPod that was set up a long time ago and what I use for iTunes. The is for my iPhone. I want to use the itunes cloud storage so i can listen to my music on my iPhone but i'm guessing that won't work if you have two id's. Of couse they'd need to match. Can you merge two id's? I would like to simplify anyway and just have one.
    Thanks.

    No.
    (106976)

  • Can i merge two Apple ID's?

    can i merge two Apple ID's?
    I have one with me.com and one neutral one.
    would love to have just the me.com Apple ID.
    How do I merge??

    You can't merge accounts, nor transfer content from one account to another account - content will remain tied to the account that bought/downloaded it.

  • How to merge two Apple IDs into one?

    Is it possible to merge two IDs into one?  I don't want to use the 'hotmail.com' extension anymore.

    No. All purchases remain tied to the AppleID used to obtain them and cannot be transferred.
    tt2

  • Merging two records in a single record for the same matnr,werks and bwart.

    Hi I have a requirement to merge two records into one single record using the quantity field from MSEG table.
    I am selecting two records from the table MSEG. Now for these two records i have to add the quantity values into one variable.
    Then there should be only one record for the same matnr,werks,bwart.
    Any suggestion would be appreciated.
    Regards,
    Amit

    hi,
    You can COLLECT statement only if all non key fields are numeric.
    This statement Adds all such fields and give us a single record.
    Regards
    Sumit Agarwal

  • Merge Two Rows of a table to One row but into two columns

    Hi
    I Am struck in writing a query to merge two rows into two columns of one row.
    Here is the Sample data i am working with,
    Col 1     Col 2     Col3 Col4 Col Col6
    5000     573-3000 2     0     Phone      
    5000     573-3036 1     0          Fax
    5000     893-5703 3     0     WOrk      
    3000     232-5656     1     0     Phone     
    3000     353-5656     2     0          FAx
    Here Col,Col3,Col4 form the Key.
    now wht i am trying to do is to Merge these type of rows put them into Columns P,F,W,E respectively to achive a Structure as below
    Col1      P     F     W
    5000     573-3000      573-3036      893-5703
    3000     232-5656     353-5656     
    Can you please help me how could i do this.
    I am pretty ordinary at writing SQL's.
    Thanks a Lot in Advance
    Message was edited by:
    Sreebhushan

    Search the forum for PIVOT and you'll find plenty of examples.

Maybe you are looking for

  • I own an iPod Touch 4th Generation. Can I download iOS 7?

    Previously it has been mentioned that he iOS 7 was not completed but there was a possibility it would be adapted for 4th gen. However, it was released over a week ago and still is unavailable. Will it ever be or is the iPod touch 4th Generation being

  • Tried PSE 8, unhappy, problems w/ PSE 5 in Win 7 Virtual

    This post is frankly my last hope with Adobe.  I loved PSE 5 in Win XP.  New computer, Win 7 Pro, backed up catalog in old computer, downloaded trial of PSE 8, unable to recover catalog, just a mass of broken links.  Took backup to another computer w

  • Calculating Total Ending Inventory

    Hello BW Gurus, I have a reporting question for you. Please reply back as soon as possible as I am nearing the deadline. The scenario is as below: I need to calculate the Total Ending Inventory and the formula is as below: Total Ending Inventory = ‘A

  • Package creation in SQL*Plus

    DB Version: 10gR2 Sometimes, we have huge Packages, stored procs to compile. I don't want the entire code of Package to be 'Echoed'. I just want to see if a particular package/SP/Function has been Compiled succesfully or not. So, i set the ECHO to of

  • SRM recipient role restricted to plants

    Hi In SRM the organizational levels available in authorizations to the 'Recipient role' consist of 'Purch.org' and 'Purch.grp'. How do I restrict the role to certain plants? I tried adding the authorization object M_BBP_IM_1 to restrict actions accor