Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / June 2005

Tip: Looking for answers? Try searching our database.

Compare objects in vectors

Thread view: 
shoa - 26 Jun 2005 00:43 GMT
Hello

I have a vector A that stores "a" objects and a vector B that stores "b"
objects. Both object "a" and "b" have one similar field "id".
Now I have to create a function to select all objects in Vector B that have
different "id" compare with objects in vector A and then do something with
them.

For example:
Vector A: have 3 objects
a1 (id=10)
a2 (id=13)
a3 (id =14)

Vector B: have 4 objects
b1 (id=10)
b2 (id =12)
b3 (id=14)
b4 (id=16)

My function will first find out object b2 and b4 (in vector B) that are not
in vector A. Then with object b2 and b4, I have to do something (update
these objects)

In my solution, I have to use two loops "for"  to find objects (b2 and b4)
then have a third vector to store (object b3 and b4 as above). Then I have
to loop (go through each object) in this third vector to update these
objects.

However, if there are many objects in Vector A nd B, it is long time to do.
Do you have a better way, please let me know
Thank you
S.Hoa
Patricia Shanahan - 26 Jun 2005 01:50 GMT
> Hello
>
[quoted text clipped - 29 lines]
> Thank you
> S.Hoa

1. Scan A, constructing a HashSet that contains all id values from A in
Integer form.

2. Scan B, looking each id up in the HashSet. If its not there, update
the B object.

Patricia
shoa - 26 Jun 2005 11:23 GMT
Thanks

> > Hello
> >
[quoted text clipped - 37 lines]
>
> Patricia


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.