I am trying to compare two Integer lists in Java, using the method retainAll, but the return is not what I expected and I don't seem to find the problem here. In the following code, within a servlet:
// some data recieved via JSon
int id_questao = Integer.valueOf(String.valueOf(resp.get("id_questao")));
ArrayList<Integer> idsAlt = (ArrayList<Integer>) resp.get("alt_selecionadas");
System.out.println(idsAlt);
// some database data
ArrayList<Integer> gabarito = new Ead_AlternativasDAO().getAlternativasCorretasPorQuestao(id_questao);
System.out.println(gabarito);
// comparing lists
ArrayList<Integer> auxiliar = new ArrayList<Integer>();
auxiliar.addAll(idsAlt);
System.out.println("auxiliar");
System.out.println(auxiliar);
auxiliar.retainAll(gabarito);
System.out.println("after retainAll: ");
System.out.println(auxiliar);
I got the following printed in debug:
idsAlt
[64, 65]
gabarito
[64, 65]
auxiliar
[64, 65]
after retainAll:
[]
It should be [64,65] also, shouldn't it? What may I be doing wrong?
ArrayList<Integer>is correct (and notArrayList<Long>, for example)?