3
I have a 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 big problems identifying how many of them there are.
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
In place of ?
he should show me the number of calculations, for example: ID 1 possui 2 calculos
.
Can someone help me, please?
How can you remove duplicates so you know the duplicate values, right? If yes, to check the frequency of each value see
#frequency
, maybe I can help you.– Bruno César
Yes, my good friend. I found this Frequency in my searches, but I was confused because I don’t know where exactly in the code I should add it and what parameters. For example, I know I have six Ids in this case. I wish I had 1 array that I could store the number of frequencies of each ID, but I can’t think of a logic for that :(
– Diego Fortes
Do you want, for example, to have a map that contains the amount of each ID? That is, in a map with key and integer value, for the key where ID 2 has value 6?
– Bruno César
Exactly, my dear! I’m glad you understand my problem, I have difficulties in clarifying things, hehe. :)
– Diego Fortes
Okay, I’ve already put it on for you and you tell me if this is what you need.
– Bruno César
Perfect, thank you very much for the consideration!
– Diego Fortes