I'm trying to write a method that takes 2 ArrayLists of doubles and returns all the values in set1 that aren't found in set2. These numbers should be returned in set3. Normally I would just use set.contains but I can only use set.get set.size and set.add. Can anyone point me in the right direction?
For example:
If set1 has the numbers 1,2,3,4,5
and set2 has the numbers 1,7,9,5,3
set3 should only contain 2,4,5
ArrayList<Double> setDiff(ArrayList<Double> set1, ArrayList<Double> set2){
ArrayList<Double> set3 = new ArrayList<Double>();
for(int i = 0; i < set1.size(); i++){
for(int x = 0; x < set2.size(); x++){
if(set1.get(i) != set2.get(x)){
set3.add(set1.get(i));
}
}
}
return set3;
}