Currently I can only get the 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 the need arises to get the same data, following the above example I want to get only the code 1
since it exists in both lists.
This is the code I use to get the different elements of two lists, and then I populate 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));
How do I get just the same, or if it is easier as I pass a list of parameters to make an appointment in the bank, these two solutions would solve my problem.