I have the following arraylist
cd1 = [3,5,7,10,15,16]
cd2 = [4,10,5,8]
The output
[3,7,15,16]
as you can see one has 6 positions and the other 4.
then if they are repeated they should be stored in another ArrayList
Code I carry:
import java.util.ArrayList;
public class inexistentes {
public static ArrayList<Integer> inexistentes(ArrayList<Integer> cd1, ArrayList<Integer> cd2){
ArrayList<Integer> newList = new ArrayList<>();
for(int i = 0; i < cd1.size(); i++){
if(cd1.contains(i) ){
newList.add(i);
}
}
return newList;
}
}
how can i buy those chains...
I already have a for but I don't know how to implement the if.
cd1.get(i)-- and see if it's in the second list.[4,8]. How would you do this if the lists had to be processed without knowing the contents of either? Imo, what you probably want isList.retainAllwhich will give[5,10]no matter how you apply it. Then you can remove those from both lists. But that has problems too. What do you do if each list multiple of the same but in different numbers in each list? Are all considered duplicates. Is it just a one-to-one thing? –