5
Currently I can only take different data from two lists, for example:
Lista X
Código 1
Código 2
Lista z:
Código 1
Código 3
I can only get the code 2
and 3
. Now arose the need to take the same data, following the example from above I want to take only the code 1
because it exists on both lists.
This is the code I use to take the different elements from two lists, and then fill a table with this data:
List<Contratos> listaContratos = listarBanco();
Cadastros cadastro = new Cadastros();
ConsultaCadastro consultaCadastro = new ConsultaCadastro();
List<Cadastros> listaCadastros;
try {
cadastro.setContratante(pesquisar.getText());
cadastro.setCodigoContrato(pesquisar.getText());
//Preenche uma lista de Cadastros
listaCadastros = consultaCadastro.buscar(cadastro);
Iterator<Cadastros> iter = listaCadastros.iterator();
while (iter.hasNext()) {
Cadastros solicitacao = iter.next();
for (Contratos s : listaContratos) {
Long t = s.getCodigoContrato();
if (t == Long.parseLong(solicitacao.getCodigoContrato())) {
iter.remove();
System.out.println("Remove");
}
}
}
tblCadastros.setItems(FXCollections.observableArrayList(listaCadastros));
Since I can only get the same ones, or if it’s easier as a list of parameters to make a query in the bank, these two solutions would solve my problem.
Let’s go continue this discussion in chat.
– Maicon Carraro
It worked perfectly, thank you.
– DiegoAugusto