I have ArrayList
with multiple numbers inside it. I need to identify how many times each number appears and then eliminate redundancies. I was able to eliminate redundancies, but I'm having great problems in identifying how many of them each has.
What you can do so far:
private List<Calculos> RemoverDuplicados()
{
aux = new ArrayList<Calculos>();
ids = new ArrayList<Integer>();
int[] intArray = new int[aux.size()];
//separa os cálculos repetidos e envia para a lista auxiliar;
for(Calculos i : calculosItems)
{
//se a variável 'ids' não tiver o valor do ID do produto, eu adiciono aqui
if(!ids.contains(Integer.valueOf(i.getId_produto())))
{
aux.add(i);
ids.add(Integer.valueOf(i.getId_produto()));
}
}
for(Calculos i : aux){
Log.d(TAG,"ID: " + i.getId_produto() + " possui: ? calculos");;
}
return aux;
}
These are the values (which are inside the database):
2
1
2
2
2
2
2
1
3
3
3
3
4
5
5
6
6
6
The current output is:
D/﹕ ~~ Calculos depois:
05-16 19:48:23.586 28643-28643/com.financeiro.coolkey.financeiro_2 D/﹕ ID: 2 possui: ? calculos
05-16 19:48:23.586 28643-28643/com.financeiro.coolkey.financeiro_2 D/﹕ ID: 1 possui: ? calculos
05-16 19:48:23.586 28643-28643/com.financeiro.coolkey.financeiro_2 D/﹕ ID: 3 possui: ? calculos
05-16 19:48:23.586 28643-28643/com.financeiro.coolkey.financeiro_2 D/﹕ ID: 4 possui: ? calculos
05-16 19:48:23.586 28643-28643/com.financeiro.coolkey.financeiro_2 D/﹕ ID: 5 possui: ? calculos
05-16 19:48:23.586 28643-28643/com.financeiro.coolkey.financeiro_2 D/﹕ ID: 6 possui: ? calculos
Instead of ?
it should show me the number of calculations, for example: ID 1 possui 2 calculos
.
Can anyone help me, please?