File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes comparing two tables Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "comparing two tables" Watch "comparing two tables" New topic

comparing two tables

sina sinchen

Joined: May 24, 2004
Posts: 9
Hello one and all,

I have two tables like

I have to compare the table I with the table II and assign the values of column II of table II to table I.For example,BR 1101 is found in table I and aslo in table II so it grabs the value of TUO-881 and write it in a new file which looks like:

I tried to read the files using IO but its getting very complicated.could u pls suggest which would be a better approach.I need to compare such tables for a huge data more than 5000 datas in a file.
[ June 04, 2004: Message edited by: Dirk Schreckmann ]
fred rosenberger
lowercase baba

Joined: Oct 02, 2003
Posts: 11955

Do you know for a fact that BR0-1101 will only occur in the second table once?

read table 2 into a hashmap, using the first field as your key.

then, as you read each line of the second file, check to see if that key is in the hashmap. if so, pull out the data, and write it to the new output.

if you don't find it, then you can either write out the two fields you have from table I, or ignore it - whichever you need to do.

does that make any sense?

There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
I agree. Here's the link:
subject: comparing two tables
It's not a secret anymore!