Good day,
I have the following code:
ArrayList<Integer> count = new ArrayList<>();
for(int i=0;i<l.size();i++)
count.add(0);
for(int i=0;i<list.size();i++)
{
for(int j=0;j<l.size();j++)
{
if(list.get(i).equals(l.get(j)))
{
int val = count.get(j);
count.set(j, val+1);
}
}
}
My problem is that when running the two for loops and comparison, it takes an extremely long time to run, since the loops I am iterating through have:
size > 150000, also both "list" and "l" are ArrayLists
Is there any way to optimize this so that the time taken to run the program decreases?
I have looked at this: for loop optimization and many more pages however the solutions don't help in my instance.
Any help would be greatly appreciated.
Aucun commentaire:
Enregistrer un commentaire