I wanted to find an intersection between two arraylist that are of byte[] format and return the common indices. I have the code as follows and it works correctly:
ArrayList<Integer> intersect = new ArrayList<Integer>();
for(int j = 0; j < A.size(); j++)
{
byte [] t = A.get(j);
for (int j1 = 0; j1 < B.size(); j1++)
{
byte[] t1 = B.get(j1);
if (Arrays.equals(t, t1))
{
intersect.add(j);
break;
}
}
}
However, as you can see, I have to use two for loops. Is there any way I can do it without using any for loops? I have tried to use "retainAll" but for some reason, it kept giving me an empty array. What can be the possible reason for that?