search for data from one table to another and print

0

Good to everyone, I have two lists that I call from a database of different tables:

listat = personNE.list();
listah = historicot2NE.list();   

        int inter1 = listat.size(); // 81 datos
        int inter2 = listah.size(); // 18 datos

What I want to do the list where it is insured compare with the list that are all the people and print those that are insured and those that are not insured I made those 2 loops but I am wrong

for (int i = 0; i < inter2; i++) {
            if (listah.get(i).getCODIGO() == listat.get(i).getCODIGO()) {
                pw.println(String.valueOf(listat.get(i).getCODIGO_DOC()
                        + "|" + listat.get(i).getCEDULA() + "|" + "0" + "|"
                        + "1" + "|" + "|" + 1 + "|"));
            }
        }

        for (int i = 0; i < inter2; i++) {

            for (int j = 0; j < inter1; j++) {
                if (listah.get(i).getCODIGO() == listat.get(j).getCODIGO()) {
                    pw.println(String.valueOf(listat.get(i).getCODIGO_DOC()
                        + "|" + listat.get(i).getCEDULA() + "|" + "0" + "|"
                        + "1" + "|" + "|" + 1 + "|"));

                }

            }

I hope your help thanks in advance.

    
asked by Dalstron 23.11.2018 в 18:21
source

1 answer

0

Ok. Following only your logic, we will invest the for, and show if and only if, I do not find listat en listah.

for (int i = 0; i < inter1; i++) { //iteramos sobre listat
    bool Encontre = false;
    for (int j = 0; j < inter2; j++) { //iteramos sobre listah
        if (listat.get(i).getCODIGO() == listah.get(j).getCODIGO()) {
            Encontre = true;
        }
    }
    if (!Encontre) { //si no lo encontre, no esta 
        pw.println(String.valueOf(listat.get(i).getCODIGO_DOC()
                        + "|" + listat.get(i).getCEDULA() + "|" + "0" + "|"
                        + "1" + "|" + "|" + 1 + "|"));
    }
}

What are we doing? the same as you did before, but with the difference that the returns are given with the changed lists. And we have a variable found, that if it finds an item on both sides, it prevents it from printing on the item that I'm iterating.

    
answered by 23.11.2018 в 18:38