Two arraylists with different size, compare them!

I Have a major problem now.
I have two text files that I read and split.
TableA:
AT1G01710.1     1     425     427     SKL
AT1G16730.1     1     200     202     SKL
AT1G20480.1     1     563     565     SKL
AT1G20510.1     1     544     546     SKL
AT1G20560.1     1     554     556     SKL
AT1G20560.2     1     476     478     SKL
TableC:
AT1G01710.1
AT1G16730.1
AT1G20480.1
AT1G20510.1
AT1G20510.2
AT1G20560.1
AT1G20560.2I have a database with the values in TableC. In table A I am interested in the 4th "column", The values before SKL. As you see; AT1G20510.2 doesn't exist in TableA. So for those values that does not exist in Table A, I just want to a add a null value. I want this output:
AT1G01710.1 \t 427
AT1G16730.1 \t 202
AT1G20480.1 \t 565
AT1G20510.1 \t 546
AT1G20510.2 \t null
AT1G20560.1 \t 556
AT1G20560.2 \t 478This is my code:
// Reads table C.
while ((line_tableC = br_tablec.readLine()) != null) {
     c_list.add(line_tableC);
// c_list size = 6
// Reads table A, and split around tabs and add "column" 4 to a list (list_size_aa).
while ((line_tableA = br_tablea.readLine()) != null) {
     a_tab_split = line_tableA.split("\\t", -1);
     a_list.add(a_tab_split[0]);
     list_size_aa.add(a_tab_split[3]);
// a_list size = 5
// Problem 1: a_list is smaller than c_list
for (int i = 0; i < a_list.size(); i++) {
          if (a_list.contains(c_list.get(i))) {
          x.add(list_size_aa.get(i));                         
         else {
     x.add("null");
       System.out.println(c_list.get(i) + "\t" + x.get(i));With this code I get this output:
AT1G01710.1 \t 427
AT1G16730.1 \t 202
AT1G20480.1 \t 565
AT1G20510.1 \t 546
AT1G20510.2 \t null
AT1G20560.1 \t 478
AT1G20560.2 \t 709Do you see the problem? In the output I get AT1G20560.1 with the corresponding value 478, but it should be 556! This is because when a_list doesn't contain a string from c_list, a null value will be added to x, and i will be incremented. Its hard to explain, maybe you see it better than I am to explain.
How can I solve this?
Best regards, knx

Last for loop should be based on table C data. In this loop your approach should be fetch each record of table C and retrieve corresponding value from table A using the key.
Here is your solution:
[*Note:* I have used HashMap to hold data of table A and also to hold result. You can use any data type of your choice, but approach will be same.]
import java.io.*;
import java.util.*;
public class Parser{
     public static void main(String[] args) throws Exception{
          System.out.println("Hello: "+System.getProperty("user.dir"));
          new Parser().parse();
     public void parse() throws Exception{
          FileReader reader1=new FileReader("TABLE_A.txt");
          BufferedReader buffer1=new BufferedReader(reader1);
          FileReader reader2=new FileReader("TABLE_C.txt");
          BufferedReader buffer2=new BufferedReader(reader2);          
          HashMap<String,String> tableAData=new HashMap<String,String>();
          List<String> tableCData=new ArrayList<String>();
          // Read data from table a          
          String data=null;
          while((data=buffer1.readLine())!=null){
               String[] temp=data.split("\\t");
               tableAData.put(temp[0],temp[3]);
          data=null;
          while((data=buffer2.readLine())!=null){               
               tableCData.add(data);
          HashMap<String, String> result=new HashMap<String, String>();          
          for(String cData: tableCData){
               if(tableAData.containsKey(cData)){
                    result.put(cData, tableAData.get(cData));
               }else{
                    result.put(cData, null);
          System.out.println("Result: "+result.toString());
}Thanks,
Mrityunjoy

Similar Messages

  • How to compare two rows from two table with different data

    how to compare two rows from two table with different data
    e.g.
    Table 1
    ID   DESC
    1     aaa
    2     bbb
    3     ccc
    Table 2
    ID   DESC
    1     aaa
    2     xxx
    3     ccc
    Result
    2

    Create
    table tab1(ID
    int ,DE char(10))
    Create
    table tab2(ID
    int ,DE char(10))
    Insert
    into tab1 Values
    (1,'aaa')
    Insert
    into tab1  Values
    (2,'bbb')
    Insert
    into tab1 Values(3,'ccc')
    Insert
    into tab1 Values(4,'dfe')
    Insert
    into tab2 Values
    (1,'aaa')
    Insert
    into tab2  Values
    (2,'xx')
    Insert
    into tab2 Values(3,'ccc')
    Insert
    into tab2 Values(6,'wdr')
    SELECT 
    tab1.ID,tab2.ID
    As T2 from tab1
    FULL
    join tab2 on tab1.ID
    = tab2.ID  
    WHERE
    BINARY_CHECKSUM(tab1.ID,tab1.DE)
    <> BINARY_CHECKSUM(tab2.ID,tab2.DE)
    OR tab1.ID
    IS NULL
    OR 
    tab2.ID IS
    NULL
    ID column considered as a primary Key
    Apart from different record,Above query populate missing record in both tables.
    Result Set
    ID ID 
    2  2
    4 NULL
    NULL 6
    ganeshk

  • Logo with percent size compared with the image

    Hello everyone
    I want to ask if there is any way to make a script that place a logo AND the size of that logo has a specific percent size (lets say 10%)
    compared with the one of the two axis of the image (lets say according to the image height).
    This is because I use to crop and reframe my photos. At the end of the edit I run my logo batch and of course every logo has different size
    compared with the size of the photo…
    Thank you all

    I want to ask if there is any way to make a script that place a logo AND the size of that logo has a specific percent size (lets say 10%) compared with the one of the two axis of the image (lets say according to the image height).
    Yes.
    What is giving you problems?

  • HT204053 I have two iphones with different numbers that I use my apple ID for purchases, etc.  How do I get my second iphone setup on icloud?  I would like to use the features of icloud for both of my iphones.  Thank you

    I have two iphones with different phone numbers that I use.  I have one of them set up on icloud now, but do not know how to set up my second device on icloud.  Both of my iphones use my same Apple ID for purchases, etc.  Is there a simple way to add a device to my icloud account?  Thank you in advance for any help someone may be able to give me.

    To move one of the phones to a different iCloud account (if that's what you want to do), go to Settings>iCloud and turn all synced data to Off.  When prompted, choose to keep the data on your iPhone.  After everything is off, scroll to the bottom and tap Delete Account.  This will delete the account from the phone but not from iCloud so the other phone will not be effected.  Then set up a new iCloud account with a different Apple ID and turn iCloud syncing in Settings>iCloud back to On.  When prompted, choose Merge.  This will upload the data to the new iCloud account.
    You will then have to go to icloud.com and sign into each iCloud account separately and delete any unwanted data that you don't want on the phone syncing with each account.

  • I have 2? How do I sync selected photos from my IPad to my IMac w/o losing all photos on my IPad and getting the phoos o my IMac. ou see I have two IMacs with different sets of photos. Also want to convert all Apple works docs to pages docs on my IMac.

    I have 2? How do I sync selected photos from my IPad to my IMac w/o losing all photos on my IPad which will be replaced with the photos on my IMac.You see I have two IMacs with different sets of photos. Also want to convert all Apple works docs to pages docs on my IMac. Is there and app available to do the former. many thanks. b

    The iPad and related software is designed to sync with only one computer. I suggest transferring the photos from one of your iMacs to the other so that all photos are on one Mac. Same for all other files you want to sync over.
    To get those AppleWorks files to the iPad you'll have to determine if Pages will open them. If it will then use the file sharing feature of iTunes to copy them to Pages on your pad.
    If Pages will not open the AppleWorks files directly you'll have to save them in some format that Pages will read. These include but may not be limited to Pages and Word formats.

  • How do i run two threads with different sleep times?

    How do i run two threads with different sleep times?
    Ive got thread A and thread B, they both update a jpanel.
    They both start when i press the start button.
    However thread A updates every 250ms and thread B updates every 1000ms. i cant just run them both at 250ms becuase this will mess it up.
    So for every four runs of thread A i want thread b to only be run once
    Does anyone know how to do this?
    Thanks, Ant...

    ok, ive done it but now i cant stop it!
    ive added buttons to start and stop, the start button works but the stop button doesnt. why doesnt "t.stop();" work?
        public void run() {
            while(t == Thread.currentThread()) {
                System.out.println("No " + t.getName());
                if (t.getName().equals("1")){
                    try {
                        t.sleep(1000); // in milliseconds
                    } catch (InterruptedException e) {}
                } else{
                    try {
                        t.sleep(250); // in milliseconds
                    } catch (InterruptedException e) {}
        }

  • Disjointed rollover with different size images?

    Every tutorial says the disjointed rollover images MUST be the same size, etc.  But for the type of photos I'm working with, it's impossible to make them the same height.  This site is exactly what I'm going for with the different sized images being used:  http://www.warmbloods-for-sale.com/HorseDetail.asp?HorseID=21333&UserID=1775.  Any idea how they accomplish this?  Or any ideas on how I can manage the same effect with different sizes in Dreamweaver CS4?

    Do a Google search for Lightbox, litebox, floatbox or look at Project Seven's Image Gallery Magic.
    Nancy O.
    Alt-Web Design & Publishing
    Web | Graphics | Print | Media  Specialists
    www.alt-web.com/
    www.twitter.com/altweb
    www.alt-web.com/blogspot.com

  • How to combine two applications with different workspaces in APEX

    Hi,
    Can anyone help out in merging two applications with different workspaces in APEX 3.2 ?
    Thanks in advance,

    Hello Satya,
    >> I am Satya …
    Please take one more step to help us and update your forum handle to something friendlier than user123… Thanks.
    >> Can anyone help out in merging two applications with different workspaces in APEX 3.2 ?
    This is not a trivial task.
    You didn’t mentioned if both workspaces sharing the same APEX instance, or they are on two different instances (machines). I believe the latter is a pre-condition to a success.
    First you need to remember that importing an APEX component, like a single page, is possible only to the same application that it was exported from. This is still valid if you have the same workspace on two separate APEX instances – one is an import of the other (which makes it an identical copy). Still, the application ID must be the same, or you’ll get the following error: “This page was exported from a different application or from an application in different workspace. Page cannot be installed in this application.”
    You can’t simply manipulating the export file, if the two workspaces are sharing the same APEX instance, as all workspaces on the same instance shares the same APEX metadata files, and you’ll receive a “unique constraint violated” error messages. That means you can’t import one application into the workspace of the other, even if you are using a different application ID.
    As far as I can see, the only viable way of doing an application merge is to have two identical workspaces, on two separate APEX instances. The two applications should share the same application ID, although this parameter can be changed in the import file. You should export the page in one application – on the first instance – and import it into the other application – on the second instance.
    You should also make sure that the exported page ID doesn’t exist on the target application, otherwise it will be replaced by the new imported page. Also, if the imported page include references to shared components that are not defined on the second application, it might also pose a problem.
    As I said, this is not trivial. The benefits are mostly depend on the amount and complexity of the pages you want to merge. If they are not many, and simple, you should consider just re-creating them on the target application. If they are very complex, the merge might fail anyway.
    Regards,
    Arie.
    Please remember to mark appropriate posts as correct/helpful. For the long run, it will benefit us all.

  • Multiple masters with DIFFERENT sizes?

    Hi,
    I think this is a NO, but I have to ask.
    Is it possible to have different master pages in a single document, each with a different size?
    If not, how do I tackly my problem?
    I am making a sales matrix and it will be comprised of 3.5 inch by 7 inch pages with some 3.5 by 3.5 inch pages interspersed throughout.
    I don't want to have two InDesign files, so it would be great if I could have masters with different sizes, OR if there was a way to use the larger of the two sizes, 3.5x7 and then set my square 3.5x3.5 pages doubled up on the larger page.
    I know I can use the 'book' feature, but sometimes that is more trouble than it's worth, especially with different size pages. What do you suggest?

    Peter,
    why do you say easier to work the other way?
    I think this spread thing may just work.
    I normally have facing pages in all of my saddlestitched letter size docs and output via Export to PDF with trim marks on. That gives me a pdf and eachpage has trim marks.
    Doing it this way with a 3.5x3.5 document and outputting spreads, I get exactly what I want. A pdf with one 7 inch page and 4 3.5 inch pages all with trim marks at the right places.
    Before I proceed though, I want to hear why this might be a bad idea....

  • I have two users with different music on each itunes and i can only use one library, how do i use both for one iTouch?

    i have two users with different music on each itunes and i can only use one library, how do i use both for one iTouch?

    Chris, I believe this link may have the information you're looking for. Welcome to discussions!
    http://docs.info.apple.com/article.html?artnum=300432

  • Can I use iCloud to sync two devices with different apples Ids?

    Can I use iCloud to sync two devices with different apple ID's

    What do you mean by "apple ID"?  There's an ID you can use at the iTunes store to buy songs, apps, etc.  there's an ID you can use for your iCloud account - the two can be different or the same. So which service are you referring to when you talk about an apple ID?

  • Can I sync two ipods with different ID on the same computer?

    can I sync two ipods with different ID on the same computer?

    Hi,
    Yes you can as long as you have two seperate user accounts on your computer. Hope this helps.
    xxmitchxx90

  • Can I sync two iPads with different users and email addresses on the same computer

    Can I sync two IPads with different users and email addresses on the same computer.

    yes, just make sure you turn off auto-sync to keep everything organized before you try syncing
    on a pc
    edit > preferences > devices - 'prevent ipads, iphones, and ipods from syncing automatically' needs to be checked

  • Can I backup two devices (with different documents) to one iCloud account?  For example: iPad and iPhone, not everything is synced between the two, but I would like to backup each (seperately in the cloud), is this possible?

    Hello Apple Community,
    Can I backup two devices (with different documents) to one iCloud account? 
    For example: iPad Air and iPhone 5, not everything is synced between the two, but I would like to backup each (seperately in the cloud).  Is this possible?
    This way when I change from an old ipad to a new, I can restore with the ipad backup, and when I change from an old iphone to a new, I can restore from the
    iphone backup.
    Thank you in advance!

    Terminology check here. Do you really mean a "CD"?  There's a difference in Cloud behavior between content from a physical CD you ripped (which only has Cloud content if you have iTunes Match) and an "album" you bought from the iTunes Store.
    Read references for Home Sharing.
    iTunes: How to share music and video - http://support.apple.com/kb/HT2688 - about Music Sharing and Home Sharing
    Home Sharing Support page - http://www.apple.com/support/homesharing/
    iOS: Setting up Home Sharing on your device - http://support.apple.com/kb/ht4557 - "With Home Sharing in iOS 4.3 or later, you can stream your entire iTunes library over your home Wi-Fi network from your Mac or PC right to your iPhone, iPad, or iPod touch."
    The above can get pretty complicated.  You are probably best off by syncing both devices to a single library and/or updating the libraries on both computers to have the same content.

  • How can I setup an .indd with two columns with different threads so that I can export to epub?

    Hi all. Sorry, english is not my native language. I´ve made an .indd: each page has two columns with different threads (is a bilingual text). When I export this .indd to .epub only appears one column from a thread following the next thread. What can i do to fix this? My indesign is CS6
    Thank you

    There are fixed format EPUB files as can be used for children's books, etc. where there are a lot of illustrations. However, those are very work-intensive to produce. I've never worked on one.
    Anne-Marie Concepcion did a Lynda.com video on producing one.
    Rorohiko produces a product called ePubCrawler which can help in produced fixed format EPUB files:
    Fixed Layout EPUB Assistant In InDesign: ePubCrawler | Rorohiko ...

Maybe you are looking for

  • How to call java function from PL/sql in oracle applications

    I am trying to call a java function from plsql procedure. Can any one explain how to call java function, and in which directory I have to store my java function in oracle applications. Do I need to register that java function from Application develop

  • Using JSP / Java to write/create an xml file

    I have been looking around the internet and in my books and I cannot find a good example of JAVA/JSP writing an XML file. I already have a recursive method that will generate the xml .. what's missing in my code now is how am i goin to append or writ

  • Tomcat: order of web-app loading

    Hi folks, does anybody know on which order Tomcat loads its web-apps ? I need a particular web-app loaded before all other web-apps. Is there a way to sepecify the loading sequence in Tomcat? Regards, Peter Menzel

  • HT201272 re-download previously purchased TV show

    I am trying to re-download a previously purchased TV show.  I do not have that TV show on my computer anywhere - I did a complete search for it. However, itunes is saying it's already on my computer. How can I re-download?

  • Feature Request:  Setting to NOT check mail on launch

    Using the Mail on the iPhone virtually locks up the device until it is done checking mail. In Settings, you can set Mail to check Manually. However, every time I launch the Mail application, it checks mail automatically. I'd like to request a setting